├── play-compute
├── public
│ ├── stylesheets
│ │ └── main.css
│ └── images
│ │ └── favicon.png
├── project
│ ├── build.properties
│ ├── plugins.sbt
│ └── Build.scala
├── .gitignore
├── app
│ ├── views
│ │ ├── index.scala.html
│ │ └── main.scala.html
│ └── controllers
│ │ └── Application.java
├── README
└── conf
│ ├── routes
│ └── application.conf
├── rackspace
├── images
│ ├── Eclipse1.png
│ ├── Eclipse2.png
│ └── Eclipse3.png
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── jclouds
│ │ └── examples
│ │ └── rackspace
│ │ ├── cloudloadbalancers
│ │ ├── Constants.java
│ │ ├── ListLoadBalancers.java
│ │ ├── DeleteLoadBalancers.java
│ │ └── UpdateLoadBalancers.java
│ │ ├── cloudservers
│ │ ├── Constants.java
│ │ ├── DeleteServer.java
│ │ └── ListServersWithFiltering.java
│ │ ├── cloudfiles
│ │ ├── Constants.java
│ │ ├── ListContainers.java
│ │ ├── CreateContainer.java
│ │ ├── ListObjects.java
│ │ ├── UploadLargeObject.java
│ │ └── DeleteObjectsAndContainer.java
│ │ ├── cloudblockstorage
│ │ ├── Constants.java
│ │ ├── ListVolumes.java
│ │ ├── ListSnapshots.java
│ │ ├── ListVolumeTypes.java
│ │ ├── DeleteVolume.java
│ │ ├── DeleteSnapshot.java
│ │ ├── ListVolumeAttachments.java
│ │ └── CreateSnapshot.java
│ │ ├── clouddns
│ │ ├── Constants.java
│ │ ├── DeleteDomains.java
│ │ ├── DeleteRecords.java
│ │ ├── ListDomains.java
│ │ ├── CreateRecords.java
│ │ ├── ListRecords.java
│ │ └── UpdateDomains.java
│ │ ├── Logging.java
│ │ └── Authentication.java
│ └── resources
│ └── logback.xml
├── README.md
├── .gitignore
├── camel-notifications
├── src
│ └── main
│ │ └── resources
│ │ ├── org
│ │ └── jclouds
│ │ │ └── camel
│ │ │ └── notifier
│ │ │ └── camel.properties
│ │ ├── logback.xml
│ │ └── META-INF
│ │ └── spring
│ │ └── camel-context.xml
└── Readme.txt
├── blobstore-clojure
├── project.clj
├── src
│ └── create_list
│ │ └── containers.clj
└── README.md
├── deploy-war-via-ant
├── runscript.sh
└── README.md
├── compute-clojure
├── project.clj
├── resources
│ └── logback.xml
├── README.md
└── src
│ └── compute_clojure
│ └── compute_examples.clj
├── chef-basics
├── src
│ └── main
│ │ ├── resources
│ │ └── logback.xml
│ │ └── assembly
│ │ └── jar-with-dependencies.xml
└── README.md
├── compute-basics
├── src
│ └── main
│ │ ├── resources
│ │ └── logback.xml
│ │ └── assembly
│ │ └── jar-with-dependencies.xml
└── README.md
├── cloudwatch-basics
├── README.md
├── src
│ └── main
│ │ └── assembly
│ │ └── jar-with-dependencies.xml
└── pom.xml
├── minecraft-compute
├── src
│ └── main
│ │ ├── resources
│ │ └── logback.xml
│ │ ├── assembly
│ │ └── jar-with-dependencies.xml
│ │ └── java
│ │ └── org
│ │ └── jclouds
│ │ └── examples
│ │ └── minecraft
│ │ ├── ConfigureMinecraftDaemon.java
│ │ ├── Utils.java
│ │ └── MinecraftController.java
└── README.md
├── ec2-windows
├── src
│ └── main
│ │ ├── resources
│ │ └── log4j.properties
│ │ ├── assembly
│ │ └── jar-with-dependencies.xml
│ │ └── java
│ │ └── org
│ │ └── jclouds
│ │ └── examples
│ │ └── ec2
│ │ └── windows
│ │ ├── Arguments.java
│ │ └── MainApp.java
└── README.md
├── blobstore-basics
├── README.md
├── src
│ └── main
│ │ └── assembly
│ │ └── jar-with-dependencies.xml
└── pom.xml
├── ec2-createlamp
├── README.md
└── pom.xml
├── ec2-computeservice-spot
├── README.md
└── pom.xml
├── blobstore-largeblob
├── README.md
└── pom.xml
├── blobstore-hdfs
├── src
│ └── main
│ │ └── java
│ │ └── org
│ │ └── jclouds
│ │ └── examples
│ │ └── blobstore
│ │ └── hdfs
│ │ ├── config
│ │ └── HdfsModule.java
│ │ └── io
│ │ ├── payloads
│ │ └── HdfsPayload.java
│ │ └── HdfsPayloadSlicer.java
└── README.md
└── blobstore-karaf-shell
├── src
└── main
│ ├── java
│ └── org
│ │ └── jclouds
│ │ └── examples
│ │ └── blobstore
│ │ └── osgi
│ │ ├── BlobStoreService.java
│ │ └── shell
│ │ ├── BlobStoreCommandSupport.java
│ │ ├── ReadCommand.java
│ │ └── WriteCommand.java
│ └── resources
│ └── OSGI-INF
│ └── blueprint
│ └── blueprint.xml
└── README.md
/play-compute/public/stylesheets/main.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/play-compute/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=0.11.2
2 |
--------------------------------------------------------------------------------
/play-compute/.gitignore:
--------------------------------------------------------------------------------
1 | logs
2 | project/project
3 | project/target
4 | target
5 | tmp
6 | .history
7 | dist
--------------------------------------------------------------------------------
/rackspace/images/Eclipse1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jclouds/legacy-jclouds-examples/HEAD/rackspace/images/Eclipse1.png
--------------------------------------------------------------------------------
/rackspace/images/Eclipse2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jclouds/legacy-jclouds-examples/HEAD/rackspace/images/Eclipse2.png
--------------------------------------------------------------------------------
/rackspace/images/Eclipse3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jclouds/legacy-jclouds-examples/HEAD/rackspace/images/Eclipse3.png
--------------------------------------------------------------------------------
/play-compute/public/images/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jclouds/legacy-jclouds-examples/HEAD/play-compute/public/images/favicon.png
--------------------------------------------------------------------------------
/play-compute/app/views/index.scala.html:
--------------------------------------------------------------------------------
1 | @(message: String)
2 |
3 | @main("Welcome to Play 2.0") {
4 |
5 | @play20.welcome(message, style = "Java")
6 |
7 | }
--------------------------------------------------------------------------------
/play-compute/README:
--------------------------------------------------------------------------------
1 | This is your new Play 2.0 application
2 | =====================================
3 |
4 | This file will be packaged with your application, when using `play dist`.
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | jclouds moved to Apache in 2013 and archived this repository. Please visit our
2 | new [JIRA issue tracker](https://issues.apache.org/jira/projects/JCLOUDS),
3 | [GitHub repository](https://github.com/jclouds/jclouds), and
4 | [web page](https://jclouds.apache.org/).
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # use glob syntax.
2 | syntax: glob
3 | target/
4 | test-output/
5 | .settings/
6 | .classpath
7 | .project
8 | .idea/
9 | atlassian-ide-plugin.xml
10 | *.iml
11 | *.ipr
12 | *.iws
13 | *.class
14 | rackspace/lib/
15 | rackspace/bin/
16 | lein
17 | project.clj
18 | .lein-deps-sum
19 |
--------------------------------------------------------------------------------
/play-compute/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | // Comment to get more information during initialization
2 | logLevel := Level.Warn
3 |
4 | // The Typesafe repository
5 | resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
6 |
7 | // Use the Play sbt plugin for Play projects
8 | addSbtPlugin("play" % "sbt-plugin" % "2.0")
--------------------------------------------------------------------------------
/camel-notifications/src/main/resources/org/jclouds/camel/notifier/camel.properties:
--------------------------------------------------------------------------------
1 | jclouds.provider=${jclouds.provider}
2 | jclouds.identity=${jclouds.identity}
3 | jclouds.credential=${jclouds.credential}
4 | smtp.username=${smtp.username}
5 | smtp.server=${smtp.server}
6 | smtp.password=${smtp.password}
7 | email.from=${email.from}
8 | email.to=${email.to}
9 |
--------------------------------------------------------------------------------
/play-compute/conf/routes:
--------------------------------------------------------------------------------
1 | # Routes
2 | # This file defines all application routes (Higher priority routes first)
3 | # ~~~~
4 |
5 | # Home page
6 | GET / controllers.Application.index()
7 |
8 | # Map static resources from the /public folder to the /assets URL path
9 | GET /assets/*file controllers.Assets.at(path="/public", file)
10 |
--------------------------------------------------------------------------------
/blobstore-clojure/project.clj:
--------------------------------------------------------------------------------
1 | (defproject blobstore-clojure "1.0-SNAPSHOT"
2 | :description "create and list buckets"
3 | :url "https://github.com/jclouds/jclouds-examples/tree/master/blobstore-clojure"
4 | :dependencies [[org.clojure/clojure "1.3.0"]
5 | [org.clojure/tools.logging "0.2.3"]
6 | [org.clojure/core.incubator "0.1.0"]
7 | [org.jclouds/jclouds-allblobstore "1.6.0"]])
8 |
--------------------------------------------------------------------------------
/play-compute/app/controllers/Application.java:
--------------------------------------------------------------------------------
1 | package controllers;
2 |
3 | import play.*;
4 | import play.mvc.*;
5 |
6 | import views.html.*;
7 |
8 | import com.google.common.collect.ImmutableSet;
9 | import org.jclouds.apis.Apis;
10 |
11 | public class Application extends Controller {
12 |
13 | public static Result index() {
14 | return ok(index.render("available apis: " + ImmutableSet.copyOf(Apis.all())));
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/deploy-war-via-ant/runscript.sh:
--------------------------------------------------------------------------------
1 | echo nameserver 208.67.222.222 >> /etc/resolv.conf
2 | apt-get update -qq
3 | apt-get upgrade -y -qq
4 | apt-get install -y -qq wget
5 | apt-get install -y -qq openjdk-6-jdk
6 | wget -q http://mirrors.axint.net/apache/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz
7 | tar xzf apache-tomcat-6.0.32.tar.gz
8 | mkdir -p /tmp/cargo/containers
9 | chmod 1777 /tmp/cargo
10 | mv apache-tomcat-6.0.32 /tmp/cargo/containers/tomcat6x
11 |
--------------------------------------------------------------------------------
/play-compute/app/views/main.scala.html:
--------------------------------------------------------------------------------
1 | @(title: String)(content: Html)
2 |
3 |
4 |
5 |
6 |
7 | @title
8 |
9 |
10 |
11 |
12 |
13 | @content
14 |
15 |
16 |
--------------------------------------------------------------------------------
/compute-clojure/project.clj:
--------------------------------------------------------------------------------
1 | (defproject compute-clojure "1.0.0.0"
2 | :description "Clojure compute examples"
3 | :dependencies [[org.clojure/clojure "1.3.0"]
4 | [org.clojure/tools.logging "0.2.3"]
5 | [org.clojure/core.incubator "0.1.0"]
6 | [org.jclouds/jclouds-allcompute "1.6.0"]
7 | [org.jclouds/driver/jclouds-sshj "1.6.0"]
8 | [org.jclouds/labs/joyentcloud "1.6.0"]
9 | [org.jclouds/driver/jclouds-slf4j "1.6.0"]
10 | [ch.qos.logback/logback-classic "1.0.0"]])
11 |
--------------------------------------------------------------------------------
/blobstore-clojure/src/create_list/containers.clj:
--------------------------------------------------------------------------------
1 | (ns create-list.containers
2 | (:use org.jclouds.blobstore2)
3 | (:import org.jclouds.blobstore.BlobStore))
4 |
5 | (defn create-and-list
6 | "create a container, then list all containers in your account"
7 | ([^String provider ^String provider-identity ^String provider-credential ^String container-to-create]
8 | (create-and-list (blobstore provider provider-identity provider-credential) container-to-create))
9 | ([^BlobStore blobstore container-to-create]
10 | (create-container blobstore container-to-create)
11 | (containers blobstore)))
12 |
13 |
--------------------------------------------------------------------------------
/compute-clojure/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/chef-basics/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/compute-basics/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/cloudwatch-basics/README.md:
--------------------------------------------------------------------------------
1 | # cloudwatch-basics
2 |
3 | This is a simple example command line client to get the total metrics stored for each of your instances the past 24 hours and shows avg/max/min CPU utilization for each instance when possible.
4 |
5 | ## Build
6 |
7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example.
8 |
9 | ## Run
10 |
11 | Invoke the jar, passing your aws credentials. Here is an example:
12 |
13 | java -jar target/cloudwatch-basics-jar-with-dependencies.jar accessKeyId secretKey
14 |
15 | ## License
16 |
17 | Copyright (C) 2009-2012 jclouds, Inc.
18 |
19 | Licensed under the Apache License, Version 2.0
20 |
--------------------------------------------------------------------------------
/minecraft-compute/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/blobstore-clojure/README.md:
--------------------------------------------------------------------------------
1 | # blobstore-clojure
2 |
3 | Basic blobstore usage example including creating a container and then listing all containers in your account.
4 |
5 | ## Build
6 |
7 | Ensure you have [Leiningen](http://github.com/technomancy/leiningen) installed, then execute 'lein deps' to grab the jclouds dependencies.
8 |
9 | ## Run
10 |
11 | bash$ lein repl
12 | user> (use 'create-list.containers)
13 | user> (create-and-list "transient" "foo" "bar" "mycontainer")
14 | or for a real blobstore like S3
15 | user> (create-and-list "aws-s3" accesskey secret "mybucket")
16 |
17 | ## License
18 |
19 | Copyright (C) 2009-2012 jclouds, Inc.
20 |
21 | Licensed under the Apache License, Version 2.0
22 |
23 |
--------------------------------------------------------------------------------
/camel-notifications/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
21 |
--------------------------------------------------------------------------------
/ec2-windows/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Set root logger level to DEBUG and its only appender to A1.
2 | log4j.rootLogger=INFO, A1
3 |
4 | # A1 is set to be a ConsoleAppender.
5 | log4j.appender.A1=org.apache.log4j.ConsoleAppender
6 |
7 | # A1 uses PatternLayout.
8 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.A1.layout.ConversionPattern=%-5p %t %c %x/ %m%n
10 |
11 | # Full logging from the example itself
12 | log4j.logger.org.jclouds.examples.ec2.windows=TRACE
13 |
14 | # Optional: increase jclouds logging
15 | #log4j.logger.jclouds=DEBUG
16 | #log4j.logger.org.jclouds=DEBUG
17 |
18 | # Optional: decrease jclouds logging a bit after increasing it!
19 | #log4j.logger.org.jclouds.rest.internal.AsyncRestClientProxy=INFO
20 | #log4j.logger.org.jclouds.http.internal.JavaUrlHttpCommandExecutorService=INFO
21 |
--------------------------------------------------------------------------------
/camel-notifications/Readme.txt:
--------------------------------------------------------------------------------
1 | # Camel Notifier
2 |
3 | This simple examples demonstrates using Apache Camel with jclouds.
4 | It starts a camel route which polls the cloud provider for running nodes.
5 | If the clouds provider gives a possitive response it sends an email to the user notifying him, that there are nodes running.
6 |
7 | # Setup
8 | The following properties need to be added the maven profile or to the project pom:
9 |
10 | jclouds.provider (ex. aws-ec2, hpcloud-compute, bluelock-vcloud-zone01)
11 | jclouds.identity (ex. accesskey, tenant:accesskey, user@org)
12 | jclouds.credential (ex. secretkey, password)
13 |
14 | smtp.username
15 | smtp.password
16 | smtp.server
17 |
18 | email.from (your email address)
19 | email.to (who this is being sent to)
20 |
21 | # Running the sample
22 |
23 | from the command line just type: mvn camel:run
24 |
--------------------------------------------------------------------------------
/compute-clojure/README.md:
--------------------------------------------------------------------------------
1 | # compute-clojure
2 |
3 | Basic usage of org.jclouds.compute2 to create a node, execute commands and destroy the node. The example below uses Amazon EC2 as provider.
4 |
5 | ## Build
6 |
7 | Ensure you have [Leiningen](http://github.com/technomancy/leiningen) installed, then execute 'lein deps' to grab the jclouds dependencies.
8 |
9 | ## Run
10 |
11 | bash$ lein repl
12 | user> (use 'org.jclouds.compute2)
13 | user> (use 'compute-clojure.compute-examples)
14 | user> (def compute (compute-service "aws-ec2" "AMAZON-IDENTITY" "AMAZON-CREDENTIAL" :slf4j :sshj))
15 | user> (create compute "example-node-group")
16 | user> (exec compute "echo hello" "example-node-group" (get-credentials))
17 | user> (destroy compute "example-node-group")
18 |
19 | ## License
20 |
21 | Copyright (C) 2009-2012 jclouds, Inc.
22 |
23 | Licensed under the Apache License, Version 2.0
24 |
--------------------------------------------------------------------------------
/play-compute/project/Build.scala:
--------------------------------------------------------------------------------
1 | import sbt._
2 | import Keys._
3 | import PlayProject._
4 |
5 | object ApplicationBuild extends Build {
6 |
7 | val appName = "play-compute"
8 | val appVersion = "1.0-SNAPSHOT"
9 |
10 | val appDependencies = Seq(
11 | "com.google.guava" % "guava" % "12.0",
12 | "org.jclouds" % "jclouds-compute" % "1.5.0-alpha.6",
13 | "org.reflections" % "reflections" % "0.9.7.RC1"
14 | //If using the securesocial module you may need to do the following to make jclouds run:
15 | //"securesocial" %% "securesocial" % "2.0.12" excludeAll(ExclusionRule(organization="org.ow2.spec.ee"), ExclusionRule(organization="com.cedarsoft"))
16 | )
17 |
18 | val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
19 | resolvers += "Maven central" at "http://repo1.maven.org/maven2/",
20 | resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
21 | )
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/blobstore-basics/README.md:
--------------------------------------------------------------------------------
1 | # blobstore-basics
2 |
3 | This is a simple example command line client that creates a container in a [BlobStore](http://code.google.com/p/jclouds/wiki/BlobStore) provider and lists the size of all the other containers.
4 |
5 | ## Build
6 |
7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example.
8 |
9 | ## Run
10 |
11 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-s3, googlestorage), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the container you'd like to create.
12 |
13 | Ex. for Amazon S3
14 |
15 | java -jar target/blobstore-basics-jar-with-dependencies.jar aws-s3 accesskey secretkey myfavoritecontainer
16 |
17 | Ex. for Rackspace CloudFiles
18 |
19 | java -jar target/blobstore-basics-jar-with-dependencies.jar cloudfiles-us username apikey myfavoritecontainer
20 |
21 |
22 | ## License
23 |
24 | Copyright (C) 2009-2012 jclouds, Inc.
25 |
26 | Licensed under the Apache License, Version 2.0
27 |
--------------------------------------------------------------------------------
/ec2-createlamp/README.md:
--------------------------------------------------------------------------------
1 | # ec2-createlamp
2 |
3 | This is a simple example command line client that creates a lamp server and everything you need to do that in [EC2](http://code.google.com/p/jclouds/wiki/EC2)
4 |
5 | ## Build
6 |
7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the sample.
8 |
9 | ## Run
10 |
11 | Invoke the jar, passing your aws credentials and the name you wish to create or destroy
12 |
13 | ### Creating your Instance
14 |
15 | The create command will create a keypair, security group, and an instance. It also blocks until the web server is running.
16 |
17 | java -jar target/ec2-createlamp-jar-with-dependencies.jar accesskey secretkey create adrianalmighty
18 |
19 | ### Destroying your Instance
20 |
21 | The destroy command will clear up the instance, key, and security group.
22 |
23 | java -jar target/ec2-createlamp-jar-with-dependencies.jar accesskey secretkey destroy adrianalmighty
24 |
25 | ## License
26 |
27 | Copyright (C) 2011 Cloud Conscious, LLC.
28 |
29 | Licensed under the Apache License, Version 2.0
30 |
--------------------------------------------------------------------------------
/ec2-windows/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jar-with-dependencies
7 |
8 | jar
9 |
10 | false
11 |
12 |
13 | metaInf-services
14 |
15 |
16 |
17 |
18 | /
19 | true
20 | true
21 | runtime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/chef-basics/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jar-with-dependencies
7 |
8 | jar
9 |
10 | false
11 |
12 |
13 | metaInf-services
14 |
15 |
16 |
17 |
18 | /
19 | true
20 | true
21 | runtime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/compute-basics/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jar-with-dependencies
7 |
8 | jar
9 |
10 | false
11 |
12 |
13 | metaInf-services
14 |
15 |
16 |
17 |
18 | /
19 | true
20 | true
21 | runtime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/blobstore-basics/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jar-with-dependencies
7 |
8 | jar
9 |
10 | false
11 |
12 |
13 | metaInf-services
14 |
15 |
16 |
17 |
18 | /
19 | true
20 | true
21 | runtime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/cloudwatch-basics/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jar-with-dependencies
7 |
8 | jar
9 |
10 | false
11 |
12 |
13 | metaInf-services
14 |
15 |
16 |
17 |
18 | /
19 | true
20 | true
21 | runtime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/minecraft-compute/src/main/assembly/jar-with-dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jar-with-dependencies
7 |
8 | jar
9 |
10 | false
11 |
12 |
13 | metaInf-services
14 |
15 |
16 |
17 |
18 | /
19 | true
20 | true
21 | runtime
22 |
23 |
24 |
--------------------------------------------------------------------------------
/ec2-computeservice-spot/README.md:
--------------------------------------------------------------------------------
1 | # ec2-computeservice-spot
2 |
3 | This is a simple example command line client that creates a spot instance in [EC2](http://code.google.com/p/jclouds/wiki/EC2) using the ComputeService interface.
4 |
5 | ## Build
6 |
7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the sample.
8 |
9 | Note you'll also need to ensure you have an ssh key in your home directory.
10 |
11 | ## Run
12 |
13 | Invoke the jar, passing your aws credentials and the name you wish to create or destroy
14 |
15 | ### Creating your Instance
16 |
17 | The create command will create a keypair, security group, and an instance in running state.
18 |
19 | java -jar target/ec2-computeservice-spot-jar-with-dependencies.jar accesskey secretkey groupname create
20 |
21 | ### Destroying your Instance
22 |
23 | The destroy command will clear up the instance, key, and security group.
24 |
25 | java -jar target/ec2-computeservice-spot-jar-with-dependencies.jar accesskey secretkey groupname destroy
26 |
27 | ## License
28 |
29 | Copyright (C) 2011 Cloud Conscious, LLC.
30 |
31 | Licensed under the Apache License, Version 2.0
32 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudloadbalancers;
20 |
21 |
22 | /**
23 | * Constants used by the Rackspace Examples.
24 | *
25 | * @author Everett Toews
26 | */
27 | public interface Constants {
28 | public static final String NAME = "jclouds-example";
29 | public static final String ZONE = "DFW";
30 | }
31 |
--------------------------------------------------------------------------------
/blobstore-largeblob/README.md:
--------------------------------------------------------------------------------
1 | # blobstore-largeblob
2 |
3 | This is a simple example command line client that creates a container in a [BlobStore](http://code.google.com/p/jclouds/wiki/BlobStore) provider and uploads a large file
4 |
5 | ## Build
6 |
7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example.
8 |
9 | ## Run
10 |
11 | Invoke the jar, passing the name of the cloud provider you with to access (aws-s3 is currently tested), identity (ex. accesskey, username), credential (ex. secretkey, password), the filename you want to upload, then the name of the container you'd like to create, then the object name and eventually the optional parameters plainhttp or securehttp and a number representing the number of threads.
12 |
13 | Ex. for Amazon S3
14 |
15 | java -jar target/blobstore-largeblob-jar-with-dependencies.jar aws-s3 accesskey secretkey inputfile myfavoritecontainer keyname plainhttp 5
16 |
17 | "plainhttp" "5" are the two optional parameters. Default values are securehttp and 4 threads.
18 |
19 | The inputfile size has to be at least 32Mbytes size to be used multipart upload. Below this size it will fall back to simple upload.
20 |
21 | ## License
22 |
23 | Copyright (C) 2009-2012 jclouds, Inc.
24 |
25 | Licensed under the Apache License, Version 2.0
26 |
--------------------------------------------------------------------------------
/blobstore-hdfs/src/main/java/org/jclouds/examples/blobstore/hdfs/config/HdfsModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Copyright (C) 2010 Cloud Conscious, LLC.
4 | *
5 | * ====================================================================
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | * ====================================================================
18 | */
19 |
20 | package org.jclouds.examples.blobstore.hdfs.config;
21 |
22 | import org.jclouds.io.PayloadSlicer;
23 |
24 | import com.google.inject.AbstractModule;
25 | import org.jclouds.examples.blobstore.hdfs.io.HdfsPayloadSlicer;
26 |
27 | public class HdfsModule extends AbstractModule {
28 |
29 | @Override
30 | protected void configure() {
31 | bind(PayloadSlicer.class).to(HdfsPayloadSlicer.class);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudservers/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudservers;
20 |
21 | import static java.util.concurrent.TimeUnit.SECONDS;
22 |
23 | /**
24 | * Constants used by the Rackspace Examples.
25 | *
26 | * @author Everett Toews
27 | */
28 | public interface Constants {
29 | public static final String NAME = "jclouds-example";
30 | public static final String ZONE = "DFW";
31 | public static final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20));
32 | }
33 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudfiles;
20 |
21 | /**
22 | * Constants used by the Rackspace Examples.
23 | *
24 | * @author Everett Toews
25 | */
26 | public interface Constants {
27 | public static final String ZONE = "DFW";
28 | public static final String CONTAINER_PUBLISH = "jclouds-example-publish";
29 | public static final String CONTAINER = "jclouds-example";
30 | public static final String FILENAME = "createObjectFromFile";
31 | public static final String SUFFIX = ".html";
32 | }
33 |
--------------------------------------------------------------------------------
/ec2-windows/README.md:
--------------------------------------------------------------------------------
1 | # Amazon EC2 Windows example
2 | This example demonstrates how to start a Windows Server instance on Amazon
3 | EC2 and obtain its randomly-generated Administrator password. Once you have
4 | this, you can log in to the server via RDP.
5 |
6 | ## Usage
7 | After building the example with `mvn assembly:assembly`, you can launch it like
8 | this:
9 |
10 | ```
11 | java -jar target/ec2-windows-jar-with-dependencies.jar --identity $AWS_API_KEY --credential $AWS_SECRET_KEY
12 | ```
13 |
14 | Replace `$AWS_API_KEY` and `$AWS_SECRET_KEY` appropriately.
15 |
16 | The following optional arguments are recognized:
17 |
18 | * `--region ` - specify the EC2 region name to launch in
19 | * `--instance-type ` - specify the EC2 instance type - defaults
20 | to `m1.small`
21 | * `--image-pattern ` - specify the pattern to select the image -
22 | this defaults to a pattern that will match the base, English, version of
23 | the current (or recent) Windows Server release.
24 |
25 | The example will start the Windows instance, wait for the encrypted password
26 | to become available, and then decrypt it. It will display the public IP
27 | address, user name (which is always Administrator) and password - you can
28 | provide these to the Remote Desktop client and log in to the new instance.
29 |
30 | Once the instance is started, the example will wait for you to hit Enter on
31 | the command line. After hitting Enter, the new instance will be shut down.
32 |
--------------------------------------------------------------------------------
/blobstore-karaf-shell/src/main/java/org/jclouds/examples/blobstore/osgi/BlobStoreService.java:
--------------------------------------------------------------------------------
1 | package org.jclouds.examples.blobstore.osgi;/*
2 | * Copyright (C) 2011 Cloud Conscious, LLC.
3 | *
4 | * ====================================================================
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | * ====================================================================
17 | */
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | * @author: iocanel
23 | */
24 | public interface BlobStoreService {
25 |
26 | /**
27 | * Reads an Object from the Blob Store.
28 | * @param bucket
29 | * @param blobName
30 | * @return
31 | */
32 | Object read(String bucket, String blobName);
33 |
34 | /**
35 | * Writes an {@link Object} to the Blob Store.
36 | * @param bucket
37 | * @param blobName
38 | * @param object
39 | */
40 | void write(String bucket, String blobName, Object object) throws IOException;
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/blobstore-karaf-shell/src/main/java/org/jclouds/examples/blobstore/osgi/shell/BlobStoreCommandSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Cloud Conscious, LLC.
3 | *
4 | * ====================================================================
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | * ====================================================================
17 | */
18 |
19 | package org.jclouds.examples.blobstore.osgi.shell;
20 |
21 | import org.apache.karaf.shell.console.OsgiCommandSupport;
22 | import org.jclouds.examples.blobstore.osgi.BlobStoreService;
23 |
24 | /**
25 | * @author: iocanel
26 | */
27 | public abstract class BlobStoreCommandSupport extends OsgiCommandSupport {
28 |
29 | protected BlobStoreService blobStoreService;
30 |
31 | public BlobStoreService getBlobStoreService() {
32 | return blobStoreService;
33 | }
34 |
35 | public void setBlobStoreService(BlobStoreService service) {
36 | this.blobStoreService = service;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/blobstore-karaf-shell/README.md:
--------------------------------------------------------------------------------
1 | # blobstore-karaf-shell
2 |
3 | This is a simple examples that demonstrates the use of blob store from within Apache Karaf Runtime.
4 | This example adds two osgi shell commands, that read and write to a blobstore. The context of the blobstore can be configured via OSGi Configuration Admin, which allows the switching blobstore contexts (providers, keys etc) "on the fly".
5 | ## Build
6 |
7 | The sample builds with maven 2.2.1 or higher (however its tested with 3.0.3). Execute 'mvn install' to build the example.
8 |
9 | ## Run
10 | From within Apache Karaf (2.2.0 or higher) type:
11 | karaf@root>osgi:install -s mvn:org.jclouds.examples/blobstore-karaf-shell/1.0-SNAPSHOT
12 |
13 | Once the sample is install, create a new configuration named "org.jclouds.blobstore" and add the provider,the access key id and the secret key.
14 |
15 | karaf@root>config:edit org.jclouds.blobstore
16 |
17 | karaf@root>config:propset provider aws-s3
18 |
19 | karaf@root>config:propset accessKeyId XXXXXX
20 |
21 | karaf@root>config:propset secretKey XXXXXX
22 |
23 | karaf@root>config:update
24 |
25 | An alternative is to create a cfg file with the key values listed above and throw it under karaf/etc.
26 |
27 | Now you can use the shell commands, for example:
28 | karaf@root>jclouds:blobstore-write mybucket myblob JCloudsRocks!
29 | karaf@root>jclouds:blobstore-read mybucket myblob
30 | JCloudsRocks!
31 |
32 | ## License
33 |
34 | Copyright (C) 2011 Cloud Conscious, LLC.
35 |
36 | Licensed under the Apache License, Version 2.0
37 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static java.util.concurrent.TimeUnit.SECONDS;
22 |
23 | /**
24 | * Constants used by the Rackspace Examples.
25 | *
26 | * @author Everett Toews
27 | */
28 | public interface Constants {
29 | public static final String NAME = "jclouds-example";
30 | public static final String ZONE = "DFW";
31 | public static final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20));
32 |
33 | public static final String ROOT = "root";
34 | public static final String PASSWORD = "sbmFPqaw5d43";
35 | public static final String DEVICE = "/dev/xvdd";
36 | }
37 |
--------------------------------------------------------------------------------
/play-compute/conf/application.conf:
--------------------------------------------------------------------------------
1 | # This is the main configuration file for the application.
2 | # ~~~~~
3 |
4 | # Secret key
5 | # ~~~~~
6 | # The secret key is used to secure cryptographics functions.
7 | # If you deploy your application to several instances be sure to use the same key!
8 | application.secret="g33@Xe@>:s_1c6K6h1SENr[8VdwyMlAV?]
54 |
55 |
--------------------------------------------------------------------------------
/blobstore-karaf-shell/src/main/java/org/jclouds/examples/blobstore/osgi/shell/ReadCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Cloud Conscious, LLC.
3 | *
4 | * ====================================================================
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | * ====================================================================
17 | */
18 |
19 | package org.jclouds.examples.blobstore.osgi.shell;
20 |
21 | import org.apache.felix.gogo.commands.Argument;
22 | import org.apache.felix.gogo.commands.Command;
23 |
24 | /**
25 | * @author: iocanel
26 | */
27 | @Command(scope = "jclouds", name = "blobstore-read", description = "Reads data from the blobstore")
28 | public class ReadCommand extends BlobStoreCommandSupport {
29 |
30 | @Argument(index = 0, name = "bucketName", description = "The name of the bucket", required = true, multiValued = false)
31 | String bucketName;
32 |
33 | @Argument(index = 1, name = "blobName", description = "The name of the blob", required = true, multiValued = false)
34 | String blobName;
35 |
36 | @Override
37 | protected Object doExecute() throws Exception {
38 | if(blobStoreService != null) {
39 | Object payload = blobStoreService.read(bucketName, blobName);
40 | System.out.printf("%s\n", payload);
41 | } else {
42 | System.err.println("No blob store service configured.");
43 | }
44 | return null;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/minecraft-compute/README.md:
--------------------------------------------------------------------------------
1 | # minecraft-compute
2 |
3 | This is a simple example command line client that creates a node in a [ComputeService](http://code.google.com/p/jclouds/wiki/ComputeGuide) provider and starts a [Minecraft](http://www.minecraft.net/) server on it.
4 |
5 | Note there are handy commands including add, list, pids, and destroy.
6 |
7 | ## Build
8 |
9 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example. Note you also need an ssh key setup in your home directory.
10 |
11 | If you don't already have ~/.ssh/id_rsa present, generate a key with the command 'ssh-keygen -t rsa' and leave the passphrase blank.
12 |
13 | ## Run
14 |
15 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-ec2, gogrid), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the group you'd like to add the node to, running minecraft.
16 |
17 | java -jar target/minecraft-compute-jar-with-dependencies.jar provider identity credential mygroup add
18 |
19 | java -jar target/minecraft-compute-jar-with-dependencies.jar provider identity credential mygroup add
20 |
21 | java -jar target/minecraft-compute-jar-with-dependencies.jar provider identity credential mygroup destroy
22 |
23 | Ex. for GleSYS
24 |
25 | java -jar target/minecraft-compute-jar-with-dependencies.jar glesys user apikey mygroup add
26 |
27 | Ex. for Amazon EC2
28 |
29 | java -jar target/minecraft-compute-jar-with-dependencies.jar aws-ec2 accesskey secretkey mygroup add
30 |
31 | ## Playing
32 |
33 | Open Minecraft, go to Multiplayer, Direct Connect, and enter the ip address of your cloud node.
34 |
35 | ## Notes
36 |
37 | If you have a firewall blocking the remote ip:25565, you will need to port forward your local 25565 (probably over ssh)
38 |
39 | Ex. if my cloud servers' ip is 15.185.168.16
40 | ssh 15.185.168.16 -L 25565:15.185.168.16:22
41 |
42 | ## License
43 |
44 | Copyright (C) 2009-2012 jclouds, Inc.
45 |
46 | Licensed under the Apache License, Version 2.0
47 |
48 |
--------------------------------------------------------------------------------
/minecraft-compute/src/main/java/org/jclouds/examples/minecraft/ConfigureMinecraftDaemon.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.jclouds.examples.minecraft;
21 |
22 | import static java.lang.String.format;
23 | import static org.jclouds.scriptbuilder.domain.Statements.exec;
24 | import static org.jclouds.scriptbuilder.domain.Statements.saveHttpResponseTo;
25 |
26 | import java.net.URI;
27 |
28 | import javax.inject.Named;
29 |
30 | import org.jclouds.scriptbuilder.InitScript;
31 |
32 | import com.google.inject.AbstractModule;
33 | import com.google.inject.Provides;
34 |
35 | /**
36 | *
37 | * @author Adrian Cole
38 | */
39 | public class ConfigureMinecraftDaemon extends AbstractModule {
40 |
41 | @Override
42 | protected void configure() {
43 |
44 | }
45 |
46 | @Provides
47 | InitScript configureMinecraftDaemon(@Named("minecraft.url") String url, @Named("minecraft.ms") int minHeap,
48 | @Named("minecraft.mx") int maxHeap) {
49 | return InitScript.builder().name("minecraft")
50 | .init(saveHttpResponseTo(URI.create(url), "${INSTANCE_HOME}", "minecraft_server.jar"))
51 | .run(exec(format("java -Xms%sm -Xmx%sm -jar minecraft_server.jar", minHeap, maxHeap))).build();
52 | }
53 |
54 |
55 | }
--------------------------------------------------------------------------------
/blobstore-hdfs/README.md:
--------------------------------------------------------------------------------
1 | # blobstore-hdfs
2 |
3 | This is a simple example which shows how we can extends the Payload to have HDFS for using with Blobstore.
4 | Then the application layer is using an upload from HDFS.
5 | The reason why such kind of HDFS payload currently is considered only an example application is that
6 | people are using different versions of Hadoop, thus the adequate version needs to be matched exactly
7 | which is not a simple decision in general case. As an example, it is the simplest way to present it.
8 |
9 | Note that, if you run this example and you will see an exception showing incompatible version between
10 | your hdfs client and the running server's hdfs version, then switch the version of hadoop-core from
11 | 0.20.2-cdh3u0 to your used version.
12 |
13 | ## Build
14 |
15 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example.
16 |
17 | ## Run
18 |
19 | First of all, you need some Hadoop running in distributed or pseudo distributed mode.
20 | The easiest way to test it, just install it a CDH3 version of Cloudera Hadoop as it is
21 | described here: https://ccp.cloudera.com/display/CDHDOC/CDH3+Deployment+in+Pseudo-Distributed+Mode
22 |
23 | Invoke the jar, passing the name of the cloud provider you with to access (aws-s3 is currently tested), identity (ex. accesskey, username), credential (ex. secretkey, password), the filename you want to upload from hfds (for example hdfs://localhost:8020/user/yourusername/yourfile), then the name of the container you'd like to create, then the object name and eventually the optional parameters plainhttp or securehttp and a number representing the number of threads.
24 |
25 | Ex. for Amazon S3
26 |
27 | "plainhttp" "5" are the two optional parameters. Default values are securehttp and 4 threads.
28 |
29 | The hdfs input file size has to be at least 32Mbytes size to be used multipart upload. Below this size it will fall back to simple upload.
30 |
31 | ## License
32 |
33 | Copyright (C) 2011 Cloud Conscious, LLC.
34 |
35 | Licensed under the Apache License, Version 2.0
36 |
--------------------------------------------------------------------------------
/blobstore-karaf-shell/src/main/java/org/jclouds/examples/blobstore/osgi/shell/WriteCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Cloud Conscious, LLC.
3 | *
4 | * ====================================================================
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | * ====================================================================
17 | */
18 |
19 | package org.jclouds.examples.blobstore.osgi.shell;
20 |
21 | import org.apache.felix.gogo.commands.Argument;
22 | import org.apache.felix.gogo.commands.Command;
23 |
24 | /**
25 | * @author: iocanel
26 | */
27 | @Command(scope = "jclouds", name = "blobstore-write", description = "Writes data from the blobstore")
28 | public class WriteCommand extends BlobStoreCommandSupport {
29 |
30 | @Argument(index = 0, name = "bucketName", description = "The name of the bucket", required = true, multiValued = false)
31 | String bucketName;
32 |
33 | @Argument(index = 1, name = "blobName", description = "The name of the blob", required = true, multiValued = false)
34 | String blobName;
35 |
36 | @Argument(index = 2, name = "payload", description = "The payload", required = true, multiValued = false)
37 | String payload;
38 |
39 |
40 | @Override
41 | protected Object doExecute() throws Exception {
42 | if(blobStoreService != null) {
43 | blobStoreService.write(bucketName,blobName,payload);
44 | } else {
45 | System.err.println("No blob store service configured.");
46 | }
47 | return null;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/rackspace/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - %m%n
6 |
7 |
8 |
9 |
10 | target/test-data/jclouds.log
11 |
12 |
13 | %d %-5p [%c] [%thread] %m%n
14 |
15 |
16 |
17 |
18 | target/test-data/jclouds-wire.log
19 |
20 |
21 | %d %-5p [%c] [%thread] %m%n
22 |
23 |
24 |
25 |
26 | target/test-data/jclouds-compute.log
27 |
28 |
29 | %d %-5p [%c] [%thread] %m%n
30 |
31 |
32 |
33 |
34 | target/test-data/jclouds-ssh.log
35 |
36 |
37 | %d %-5p [%c] [%thread] %m%n
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/blobstore-karaf-shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/Constants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import java.util.regex.Matcher;
22 | import java.util.regex.Pattern;
23 |
24 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
25 |
26 | import com.google.common.base.Function;
27 | import com.google.common.base.Predicate;
28 |
29 |
30 | /**
31 | * Constants used by the Rackspace Examples.
32 | *
33 | * @author Everett Toews
34 | */
35 | public interface Constants {
36 | public static final String NAME = "jclouds-example.com";
37 | public static final String ALT_NAME = "alt-jclouds-example.com";
38 | public static final String CLOUD_SERVERS = "cloudServersOpenStack";
39 |
40 | // subdomains contain two or more '.'
41 | public static final Pattern SUBDOMAIN_PATTERN = Pattern.compile(".*\\..*\\.");
42 |
43 | /**
44 | * Determine if a domain is a top level domain (i.e. not a subdomain).
45 | */
46 | public static final Predicate IS_DOMAIN = new Predicate() {
47 | public boolean apply(Domain domain) {
48 | Matcher matcher = SUBDOMAIN_PATTERN.matcher(domain.getName());
49 | return !matcher.find();
50 | }
51 | };
52 |
53 | /**
54 | * Take a Domain and return its id.
55 | */
56 | public static final Function GET_DOMAIN_ID = new Function() {
57 | public Integer apply(Domain domain) {
58 | return domain.getId();
59 | }
60 | };
61 | }
62 |
--------------------------------------------------------------------------------
/compute-clojure/src/compute_clojure/compute_examples.clj:
--------------------------------------------------------------------------------
1 | (ns compute-clojure.compute-examples
2 | (:use
3 | [org.jclouds.compute2]
4 | [clojure.java.io])
5 | (:import
6 | [org.jclouds.domain LoginCredentials]
7 | [org.jclouds.scriptbuilder InitBuilder]
8 | [org.jclouds.compute.options TemplateOptions$Builder]
9 | [org.jclouds.scriptbuilder.domain Statement Statements]
10 | [org.jclouds.scriptbuilder.statements.login AdminAccess]))
11 |
12 | (defn print-nodes-in-group [compute group]
13 | (let [nodes (nodes-with-details-matching compute #(= group (.getGroup %)))]
14 | (map #(println (format "<< node %s private ips:%s public-ips:%s%n" (.getId %) (private-ips %) (public-ips %))) nodes)))
15 |
16 | (defn get-credentials []
17 | (-> (LoginCredentials/builder)
18 | (.user (System/getProperty "user.name"))
19 | (.privateKey (slurp (str (System/getProperty "user.home") "/.ssh/id_rsa") :encoding "utf-8"))
20 | (.build)))
21 |
22 | (defn options [login]
23 | (-> (TemplateOptions$Builder/overrideLoginCredentials login)
24 | (.runAsRoot false)
25 | (.wrapInInitScript false)))
26 |
27 | (defn print-exec-response [response]
28 | (let [node (key response)
29 | output (val response)]
30 | (println (format "<< node: %s %s %s %s%n" (.getId node) (private-ips node) (public-ips node) output))))
31 |
32 | (defn create [compute group]
33 | "Create a new node in the given group"
34 | (do
35 | (println (format ">> adding node to group: %s%n" group))
36 | (let [response (create-node compute group (TemplateOptions$Builder/runScript (AdminAccess/standard)))]
37 | (println (format "<< %s%n" response))
38 | response)))
39 |
40 | (defn exec [compute command group login]
41 | "Execute command for the given group, using login"
42 | (do
43 | (println (format ">> running [%s] on group %s as %s%n" command group (.getUser login)))
44 | (let [responses (run-script-on-nodes-matching compute (in-group? group) (Statements/exec command) (options login))]
45 | (map print-exec-response responses)
46 | responses)))
47 |
48 | (defn destroy [compute group]
49 | "Destroy all nodes in the given group"
50 | (do
51 | (println (format ">> destroying nodes in group %s%n" group))
52 | (let [responses (destroy-nodes-matching compute (in-group? group))]
53 | (map #(println (format "<< %s%n" %)) responses)
54 | responses)))
55 |
--------------------------------------------------------------------------------
/blobstore-hdfs/src/main/java/org/jclouds/examples/blobstore/hdfs/io/payloads/HdfsPayload.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Copyright (C) 2010 Cloud Conscious, LLC.
4 | *
5 | * ====================================================================
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | * ====================================================================
18 | */
19 |
20 | package org.jclouds.examples.blobstore.hdfs.io.payloads;
21 |
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 |
25 | import org.apache.hadoop.conf.Configuration;
26 | import org.apache.hadoop.fs.FileSystem;
27 | import org.apache.hadoop.fs.Path;
28 | import org.jclouds.io.payloads.BasePayload;
29 |
30 | import com.google.common.base.Throwables;
31 |
32 | public class HdfsPayload extends BasePayload {
33 |
34 | private Configuration configuration;
35 |
36 | public HdfsPayload(final Path content, final Configuration configuration)
37 | throws IOException {
38 | this(content, configuration, content.getFileSystem(configuration)
39 | .getFileStatus(content).getLen());
40 | }
41 |
42 | public HdfsPayload(final Path content, final Configuration configuration,
43 | final long length) throws IOException {
44 | super(content);
45 | this.configuration = configuration;
46 | getContentMetadata().setContentLength(length);
47 | }
48 |
49 | public InputStream getInput() {
50 | try {
51 | return content.getFileSystem(configuration).open(content);
52 | } catch (IOException e) {
53 | Throwables.propagate(e);
54 | return null;
55 | }
56 | }
57 |
58 | public FileSystem getFileSystem() throws IOException {
59 | return content.getFileSystem(configuration);
60 | }
61 |
62 | public Configuration getConfiguration() {
63 | return configuration;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/Arguments.java:
--------------------------------------------------------------------------------
1 | package org.jclouds.examples.ec2.windows;
2 |
3 | import org.jclouds.ec2.domain.InstanceType;
4 | import org.kohsuke.args4j.Option;
5 |
6 | /**
7 | * A javabean that represents the application's command line arguments.
8 | *
9 | * @author Richard Downer
10 | */
11 | public class Arguments {
12 | private String identity;
13 | private String credential;
14 | private String region;
15 | private static final String IMAGE_NAME_PATTERN_DEFAULT = "Windows_Server-2008-R2_SP1-English-64Bit-Base-";
16 | private String imageNamePattern = IMAGE_NAME_PATTERN_DEFAULT;
17 | private static final String INSTANCE_TYPE_DEFAULT = InstanceType.M1_SMALL;
18 | private String instanceType = INSTANCE_TYPE_DEFAULT;
19 | private static final String AMI_OWNER_DEFAULT = "801119661308";
20 | private String amiOwner = AMI_OWNER_DEFAULT;
21 |
22 | public String getIdentity() {
23 | return identity;
24 | }
25 |
26 | public String getCredential() {
27 | return credential;
28 | }
29 |
30 | public String getRegion() {
31 | return region;
32 | }
33 |
34 | public String getImageNamePattern() {
35 | return imageNamePattern;
36 | }
37 |
38 | public String getInstanceType() {
39 | return instanceType;
40 | }
41 |
42 | public String getAmiOwner() {
43 | return amiOwner;
44 | }
45 |
46 | @Option(name = "--identity", aliases = "-i", required = true, usage = "your AWS access key ID")
47 | public void setIdentity(String identity) {
48 | this.identity = identity;
49 | }
50 |
51 | @Option(name = "--credential", aliases = "-c", required = true, usage = "your AWS secret access key")
52 | public void setCredential(String credential) {
53 | this.credential = credential;
54 | }
55 |
56 | @Option(name = "--region", aliases = "-r", required = true, usage = "AWS region name")
57 | public void setRegion(String region) {
58 | this.region = region;
59 | }
60 |
61 | @Option(name = "--image-pattern", aliases = "-p", usage = "regular expression to select an AMI; default=" + IMAGE_NAME_PATTERN_DEFAULT)
62 | public void setImageNamePattern(String imageNamePattern) {
63 | this.imageNamePattern = imageNamePattern;
64 | }
65 |
66 | @Option(name = "--instance-type", aliases = "-t", usage = "instance type; default=" + INSTANCE_TYPE_DEFAULT)
67 | public void setInstanceType(String instanceType) {
68 | this.instanceType = instanceType;
69 | }
70 |
71 | @Option(name = "--ami-owner", aliases = "-o", usage = "AMI owner account ID; default=" + AMI_OWNER_DEFAULT)
72 | public void setAmiOwner(String amiOwner) {
73 | this.amiOwner = amiOwner;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/blobstore-hdfs/src/main/java/org/jclouds/examples/blobstore/hdfs/io/HdfsPayloadSlicer.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Copyright (C) 2010 Cloud Conscious, LLC.
4 | *
5 | * ====================================================================
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | * ====================================================================
18 | */
19 |
20 | package org.jclouds.examples.blobstore.hdfs.io;
21 |
22 | import static com.google.common.base.Preconditions.checkArgument;
23 | import static com.google.common.base.Preconditions.checkNotNull;
24 |
25 | import java.io.IOException;
26 | import java.io.InputStream;
27 |
28 | import javax.inject.Singleton;
29 |
30 | import org.apache.hadoop.fs.FSDataInputStream;
31 | import org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload;
32 | import org.jclouds.io.Payload;
33 | import org.jclouds.io.internal.BasePayloadSlicer;
34 | import org.jclouds.io.payloads.InputStreamSupplierPayload;
35 |
36 | import com.google.common.io.Closeables;
37 | import com.google.common.io.InputSupplier;
38 | import com.google.common.io.LimitInputStream;
39 |
40 | @Singleton
41 | public class HdfsPayloadSlicer extends BasePayloadSlicer {
42 |
43 | @Override
44 | public Payload slice(Payload input, long offset, long length) {
45 | checkNotNull(input);
46 | checkArgument(offset >= 0, "offset is negative");
47 | checkArgument(length >= 0, "length is negative");
48 | Payload returnVal;
49 | if (input instanceof HdfsPayload) {
50 | returnVal = doSlice(
51 | (FSDataInputStream) ((HdfsPayload) input).getInput(), offset,
52 | length);
53 | return copyMetadataAndSetLength(input, returnVal, length);
54 | } else {
55 | return super.slice(input, offset, length);
56 | }
57 | }
58 |
59 | protected Payload doSlice(final FSDataInputStream inputStream,
60 | final long offset, final long length) {
61 | return new InputStreamSupplierPayload(new InputSupplier() {
62 | public InputStream getInput() throws IOException {
63 | if (offset > 0) {
64 | try {
65 | inputStream.seek(offset);
66 | } catch (IOException e) {
67 | Closeables.closeQuietly(inputStream);
68 | throw e;
69 | }
70 | }
71 | return new LimitInputStream(inputStream, length);
72 | }
73 | });
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/cloudwatch-basics/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
24 | 4.0.0
25 | org.jclouds.examples
26 | cloudwatch-basics
27 | 1.0-SNAPSHOT
28 | cloudwatch-basics
29 | jclouds cloudwatch example
30 |
31 |
32 |
33 | org.jclouds.provider
34 | aws-ec2
35 | 1.5.0-beta.3
36 |
37 |
38 | org.jclouds.provider
39 | aws-cloudwatch
40 | 1.5.0-beta.3
41 |
42 |
43 |
44 |
45 | ${project.artifactId}
46 |
47 |
48 |
49 | org.apache.maven.plugins
50 | maven-jar-plugin
51 |
52 |
53 |
54 | org.jclouds.examples.cloudwatch.basics.MainApp
55 |
56 |
57 |
58 |
59 |
60 |
61 | maven-assembly-plugin
62 | 2.2.1
63 |
64 |
65 | src/main/assembly/jar-with-dependencies.xml
66 |
67 |
68 |
69 | org.jclouds.examples.cloudwatch.basics.MainApp
70 |
71 |
72 |
73 |
74 |
75 | make-assembly
76 | package
77 |
78 | single
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/minecraft-compute/src/main/java/org/jclouds/examples/minecraft/Utils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.jclouds.examples.minecraft;
21 |
22 | import static com.google.common.base.Charsets.UTF_8;
23 | import static com.google.common.base.Throwables.propagate;
24 | import static com.google.common.collect.Iterables.get;
25 | import static org.jclouds.compute.options.TemplateOptions.Builder.runAsRoot;
26 |
27 | import java.io.File;
28 | import java.io.IOException;
29 |
30 | import org.jclouds.compute.domain.ExecResponse;
31 | import org.jclouds.compute.domain.NodeMetadata;
32 | import org.jclouds.compute.options.TemplateOptions;
33 | import org.jclouds.domain.LoginCredentials;
34 |
35 | import com.google.common.base.Function;
36 | import com.google.common.io.Files;
37 | import com.google.common.net.HostAndPort;
38 |
39 | /**
40 | *
41 | * @author Adrian Cole
42 | */
43 | public class Utils {
44 | public static Function getStdout() {
45 | return new Function() {
46 |
47 | @Override
48 | public String apply(ExecResponse input) {
49 | return input.getOutput();
50 | }
51 | };
52 | }
53 |
54 | public static Function firstPublicAddressToHostAndPort(final int port) {
55 | return new Function() {
56 |
57 | @Override
58 | public HostAndPort apply(NodeMetadata input) {
59 | return HostAndPort.fromParts(get(input.getPublicAddresses(), 0), port);
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return "firstPublicAddressToHostAndPort(" + port + ")";
65 | }
66 |
67 | };
68 | }
69 |
70 | public static TemplateOptions asCurrentUser() {
71 | return runAsRoot(false).overrideLoginCredentials(currentUser());
72 | }
73 |
74 | public static LoginCredentials currentUser() {
75 | String privateKeyKeyFile = System.getProperty("user.home") + "/.ssh/id_rsa";
76 | String privateKey;
77 | try {
78 | privateKey = Files.toString(new File(privateKeyKeyFile), UTF_8);
79 | } catch (IOException e) {
80 | throw propagate(e);
81 | }
82 | assert privateKey.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + privateKey;
83 | return LoginCredentials.builder().user(System.getProperty("user.name")).privateKey(privateKey).build();
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/compute-basics/README.md:
--------------------------------------------------------------------------------
1 | # compute-basics
2 |
3 | This is a simple example command line client that creates a node in a [ComputeService](http://www.jclouds.org/documentation/userguide/compute/) provider and executes `echo hello` on everything in its group.
4 |
5 | ## Build
6 |
7 | Ensure you have **maven 3.02** or higher installed, then execute `mvn install` to build the example.
8 | Note you also need an ssh key setup in your home directory.
9 |
10 | If you don't already have `~/.ssh/id_rsa` present, generate a key with the command `ssh-keygen -t rsa` and leave the passphrase blank.
11 |
12 | ## Run
13 |
14 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-ec2, gogrid), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the group you'd like to add the node to.
15 |
16 | The 4th parameter represents the **action** you want to run. Supported actions are:
17 |
18 | - add
19 | - exec
20 | - destroy
21 |
22 | Noting that **destroy** will destroy all nodes in the group. If the 4th parameter is exec, you must quote a command to execute across the group of nodes.
23 |
24 | To add a node to the group *mygroup*:
25 |
26 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup add
27 |
28 | To execute a command to all nodes of the group *mygroup*:
29 |
30 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup exec "echo hello"
31 |
32 | To destroy all nodes of the group *mygroup*:
33 |
34 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup destroy
35 |
36 | ### Amazon EC2
37 |
38 | java -jar target/compute-basics-jar-with-dependencies.jar aws-ec2 \
39 | accesskey secretkey mygroup add
40 |
41 | ### HP Cloud
42 |
43 | java -jar target/compute-basics-jar-with-dependencies.jar hpcloud-compute \
44 | tenantId:accesskey secretkey mygroup add
45 |
46 | ### TryStack.org
47 |
48 | java -jar target/compute-basics-jar-with-dependencies.jar trystack-nova tenantId:user password mygroup add
49 |
50 | ### Your own OpenStack Nova
51 |
52 | java -jar target/compute-basics-jar-with-dependencies.jar openstack-nova \
53 | -Dopenstack-nova.image-id=RegionOne/15 \
54 | -Dopenstack-nova.login-user=ubuntu \
55 | -Djclouds.trust-all-certs=true \
56 | -Djclouds.keystone.credential-type=passwordCredentials \
57 | -Dopenstack-nova.endpoint=https://keystone:35357 \
58 | tenantId:user password mygroup add
59 |
60 | ### Virtualbox
61 |
62 | java -jar target/compute-basics-jar-with-dependencies.jar virtualbox \
63 | your-username your-password mygroup add
64 |
65 | ### Your own OpenStack Nova emulating EC2
66 |
67 | java -jar target/compute-basics-jar-with-dependencies.jar openstack-nova-ec2 \
68 | -Dopenstack-nova-ec2.image-id=nova/ami-00000009 \
69 | -Dopenstack-nova-ec2.login-user=ubuntu \
70 | -Djclouds.trust-all-certs=true \
71 | -Dopenstack-nova-ec2.endpoint=https://novahost/services/Cloud \
72 | tenantId:accesskey secretkey mygroup add
73 |
74 | ## License
75 |
76 | Copyright (C) 2009-2012 jclouds, Inc.
77 |
78 | Licensed under the Apache License, Version 2.0
79 |
--------------------------------------------------------------------------------
/ec2-createlamp/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
25 | 4.0.0
26 | org.jclouds.examples
27 | ec2-createlamp
28 | 1.0.0
29 | ec2-createlamp
30 | jclouds ec2 example that creates an instance and all you need to access it
31 |
32 |
33 |
34 | org.jclouds.provider
35 | aws-ec2
36 | 1.5.0
37 |
38 |
39 |
40 | ${project.artifactId}
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-jar-plugin
46 |
47 |
48 |
49 | org.jclouds.examples.ec2.createlamp.MainApp
50 |
51 |
52 |
53 |
54 |
55 |
56 | maven-assembly-plugin
57 |
58 |
59 | jar-with-dependencies
60 |
61 |
62 |
63 | org.jclouds.examples.ec2.createlamp.MainApp
64 |
65 |
66 |
67 |
68 |
69 | make-assembly
70 | package
71 |
72 | single
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/ec2-computeservice-spot/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
25 | 4.0.0
26 | org.jclouds.examples
27 | ec2-computeservice-spot
28 | 1.0.0
29 | ec2-computeservice-spot
30 | jclouds ec2 example that creates a spot instance using the ComputeService
31 |
32 |
33 |
34 | org.jclouds.provider
35 | aws-ec2
36 | 1.1.0
37 |
38 |
39 |
40 |
41 | ${project.artifactId}
42 |
43 |
44 |
45 | org.apache.maven.plugins
46 | maven-jar-plugin
47 |
48 |
49 |
50 | org.jclouds.examples.ec2.spot.MainApp
51 |
52 |
53 |
54 |
55 |
56 |
57 | maven-assembly-plugin
58 |
59 |
60 | jar-with-dependencies
61 |
62 |
63 |
64 | org.jclouds.examples.ec2.spot.MainApp
65 |
66 |
67 |
68 |
69 |
70 | make-assembly
71 | package
72 |
73 | single
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/chef-basics/README.md:
--------------------------------------------------------------------------------
1 | # chef-basics
2 |
3 | This is a simple example command line client that creates a node in a [ComputeService](http://code.google.com/p/jclouds/wiki/ComputeGuide) provider and installs an Apache web server on everything in its group using Chef.
4 |
5 | ## Build
6 |
7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example. Note you also need an ssh key setup in your home directory.
8 |
9 | If you don't already have ~/.ssh/id_rsa present, generate a key with the command 'ssh-keygen -t rsa' and leave the passphrase blank.
10 |
11 | Also make sure you have the private keys for the client and validator if you are using a Chef Server.
12 |
13 | ## Run
14 |
15 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-ec2, gogrid), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the group you'd like to add the node to. The 5th parameter must be add, chef or destroy, noting that destroy will destroy all nodes in the group. If the 5th parameter is chef or solo, you must provide the list of recipes to install, separated by commas.
16 |
17 | Also, if the 5th parameter is 'chef', you must provide the connection details to the chef server. See the examples below:
18 |
19 | java -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup add
20 |
21 | java -Dchef.endpoint=http://chefendpoint -Dchef.client=clientname -Dchef.validator=validatorname -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup chef apache2
22 |
23 | java -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup solo apache2
24 |
25 | java -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup destroy
26 |
27 | Ex. for Amazon EC2
28 |
29 | java -jar target/chef-basics-jar-with-dependencies.jar aws-ec2 accesskey secretkey mygroup add
30 |
31 | Ex. for HP Cloud
32 |
33 | java -jar target/chef-basics-jar-with-dependencies.jar hpcloud-compute tenantId:accesskey secretkey mygroup add
34 |
35 | Ex. for TryStack.org
36 |
37 | java -jar target/chef-basics-jar-with-dependencies.jar trystack-nova tenantId:user password mygroup add
38 |
39 | Ex. for Abiquo
40 |
41 | java -Dabiquo.endpoint=http://abiquohost/api -jar target/chef-basics-jar-with-dependencies.jar abiquo user password mygroup add
42 |
43 | Ex. for your own OpenStack Nova
44 |
45 | java -Dopenstack-nova.image-id=RegionOne/15 -Dopenstack-nova.login-user=ubuntu -Djclouds.trust-all-certs=true -Djclouds.keystone.credential-type=passwordCredentials -Dopenstack-nova.endpoint=https://keystone:35357 -jar target/chef-basics-jar-with-dependencies.jar openstack-nova tenantId:user password mygroup add
46 |
47 | Ex. for Virtualbox
48 | java -jar target/chef-basics-jar-with-dependencies.jar virtualbox vboxwebsrv-username vboxwebsrv-password mygroup add
49 |
50 | Ex. for your own OpenStack Nova emulating EC2
51 |
52 | java -Dopenstack-nova-ec2.image-id=nova/ami-00000009 -Dopenstack-nova-ec2.login-user=ubuntu -Djclouds.trust-all-certs=true -Dopenstack-nova-ec2.endpoint=https://novahost/services/Cloud -jar target/chef-basics-jar-with-dependencies.jar openstack-nova-ec2 tenantId:accesskey secretkey mygroup add
53 |
54 | ## License
55 |
56 | Copyright (C) 2009-2012 jclouds, Inc.
57 |
58 | Licensed under the Apache License, Version 2.0
59 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/ListLoadBalancers.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudloadbalancers;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import org.jclouds.ContextBuilder;
24 | import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
25 | import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
26 | import org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi;
27 |
28 | /**
29 | * This example lists all Load Balancers.
30 | *
31 | * @author Everett Toews
32 | */
33 | public class ListLoadBalancers {
34 | private CloudLoadBalancersApi clb;
35 |
36 | /**
37 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
38 | *
39 | * The first argument (args[0]) must be your username
40 | * The second argument (args[1]) must be your API key
41 | */
42 | public static void main(String[] args) {
43 | ListLoadBalancers listLoadBalancers = new ListLoadBalancers();
44 |
45 | try {
46 | listLoadBalancers.init(args);
47 | listLoadBalancers.listLoadBalancers();
48 | }
49 | catch (Exception e) {
50 | e.printStackTrace();
51 | }
52 | finally {
53 | listLoadBalancers.close();
54 | }
55 | }
56 |
57 | private void init(String[] args) {
58 | // The provider configures jclouds To use the Rackspace Cloud (US)
59 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudloadbalancers-uk"
60 | String provider = "rackspace-cloudloadbalancers-us";
61 |
62 | String username = args[0];
63 | String apiKey = args[1];
64 |
65 | clb = ContextBuilder.newBuilder(provider)
66 | .credentials(username, apiKey)
67 | .buildApi(CloudLoadBalancersApi.class);
68 | }
69 |
70 | private void listLoadBalancers() {
71 | System.out.println("List Load Balancers");
72 |
73 | for (String zone: clb.getConfiguredZones()) {
74 | System.out.println(" " + zone);
75 |
76 | LoadBalancerApi lbApi = clb.getLoadBalancerApiForZone(zone);
77 |
78 | for (LoadBalancer loadBalancer: lbApi.list().concat()) {
79 | System.out.println(" " + loadBalancer);
80 | }
81 | }
82 | }
83 |
84 | /**
85 | * Always close your service when you're done with it.
86 | */
87 | public void close() {
88 | closeQuietly(clb);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/ListContainers.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudfiles;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.blobstore.BlobStore;
28 | import org.jclouds.blobstore.BlobStoreContext;
29 | import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
30 | import org.jclouds.openstack.swift.CommonSwiftClient;
31 | import org.jclouds.openstack.swift.domain.ContainerMetadata;
32 | import org.jclouds.rest.RestContext;
33 |
34 | /**
35 | * List the object storage containers associated with your account.
36 | *
37 | * @author Everett Toews
38 | */
39 | public class ListContainers implements Closeable {
40 | private BlobStore storage;
41 | private RestContext swift;
42 |
43 | /**
44 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
45 | *
46 | * The first argument (args[0]) must be your username
47 | * The second argument (args[1]) must be your API key
48 | */
49 | public static void main(String[] args) {
50 | ListContainers listContainers = new ListContainers();
51 |
52 | try {
53 | listContainers.init(args);
54 | listContainers.listContainers();
55 | }
56 | finally {
57 | listContainers.close();
58 | }
59 | }
60 |
61 | private void init(String[] args) {
62 | // The provider configures jclouds To use the Rackspace Cloud (US)
63 | // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
64 | String provider = "cloudfiles-us";
65 |
66 | String username = args[0];
67 | String apiKey = args[1];
68 |
69 | BlobStoreContext context = ContextBuilder.newBuilder(provider)
70 | .credentials(username, apiKey)
71 | .buildView(BlobStoreContext.class);
72 | storage = context.getBlobStore();
73 | swift = context.unwrap();
74 | }
75 |
76 | private void listContainers() {
77 | System.out.println("List Containers");
78 | Set containers = swift.getApi().listContainers();
79 |
80 | for (ContainerMetadata container: containers) {
81 | System.out.println(" " + container);
82 | }
83 | }
84 |
85 | /**
86 | * Always close your service when you're done with it.
87 | */
88 | public void close() {
89 | closeQuietly(storage.getContext());
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListVolumes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.openstack.cinder.v1.CinderApi;
28 | import org.jclouds.openstack.cinder.v1.CinderApiMetadata;
29 | import org.jclouds.openstack.cinder.v1.CinderAsyncApi;
30 | import org.jclouds.openstack.cinder.v1.domain.Volume;
31 | import org.jclouds.rest.RestContext;
32 |
33 | /**
34 | * This example lists all volumes.
35 | *
36 | * @author Everett Toews
37 | */
38 | public class ListVolumes implements Closeable {
39 | private RestContext cinder;
40 | private Set zones;
41 |
42 | /**
43 | * To get a username and API key see
44 | * http://www.jclouds.org/documentation/quickstart/rackspace/
45 | *
46 | * The first argument (args[0]) must be your username The second argument
47 | * (args[1]) must be your API key
48 | */
49 | public static void main(String[] args) {
50 | ListVolumes listVolumes = new ListVolumes();
51 |
52 | try {
53 | listVolumes.init(args);
54 | listVolumes.listVolumes();
55 | }
56 | catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | finally {
60 | listVolumes.close();
61 | }
62 | }
63 |
64 | private void init(String[] args) {
65 | // The provider configures jclouds To use the Rackspace Cloud (US)
66 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudblockstorage-uk"
67 | String provider = "rackspace-cloudblockstorage-us";
68 |
69 | String username = args[0];
70 | String apiKey = args[1];
71 |
72 | cinder = ContextBuilder.newBuilder(provider)
73 | .credentials(username, apiKey)
74 | .build(CinderApiMetadata.CONTEXT_TOKEN);
75 | zones = cinder.getApi().getConfiguredZones();
76 | }
77 |
78 | private void listVolumes() {
79 | System.out.println("List Volumes");
80 |
81 | for (String zone: zones) {
82 | System.out.println(" " + zone);
83 |
84 | for (Volume volume: cinder.getApi().getVolumeApiForZone(zone).listInDetail()) {
85 | System.out.println(" " + volume);
86 | }
87 | }
88 | }
89 |
90 | /**
91 | * Always close your service when you're done with it.
92 | */
93 | public void close() {
94 | closeQuietly(cinder);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListSnapshots.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.openstack.cinder.v1.CinderApi;
28 | import org.jclouds.openstack.cinder.v1.CinderApiMetadata;
29 | import org.jclouds.openstack.cinder.v1.CinderAsyncApi;
30 | import org.jclouds.openstack.cinder.v1.domain.Snapshot;
31 | import org.jclouds.rest.RestContext;
32 |
33 | /**
34 | * This example lists all of your snapshots.
35 | *
36 | * @author Everett Toews
37 | */
38 | public class ListSnapshots implements Closeable {
39 | private RestContext cinder;
40 | private Set zones;
41 |
42 | /**
43 | * To get a username and API key see
44 | * http://www.jclouds.org/documentation/quickstart/rackspace/
45 | *
46 | * The first argument (args[0]) must be your username The second argument
47 | * (args[1]) must be your API key
48 | */
49 | public static void main(String[] args) {
50 | ListSnapshots listSnapshots = new ListSnapshots();
51 |
52 | try {
53 | listSnapshots.init(args);
54 | listSnapshots.listSnapshots();
55 | }
56 | catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | finally {
60 | listSnapshots.close();
61 | }
62 | }
63 |
64 | private void init(String[] args) {
65 | // The provider configures jclouds To use the Rackspace Cloud (US)
66 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudblockstorage-uk"
67 | String provider = "rackspace-cloudblockstorage-us";
68 |
69 | String username = args[0];
70 | String apiKey = args[1];
71 |
72 | cinder = ContextBuilder.newBuilder(provider)
73 | .credentials(username, apiKey)
74 | .build(CinderApiMetadata.CONTEXT_TOKEN);
75 | zones = cinder.getApi().getConfiguredZones();
76 | }
77 |
78 | private void listSnapshots() {
79 | System.out.println("List Snapshots");
80 |
81 | for (String zone: zones) {
82 | System.out.println(" " + zone);
83 |
84 | for (Snapshot snapshot: cinder.getApi().getSnapshotApiForZone(zone).listInDetail()) {
85 | System.out.println(" " + snapshot);
86 | }
87 | }
88 | }
89 |
90 | /**
91 | * Always close your service when you're done with it.
92 | */
93 | public void close() {
94 | closeQuietly(cinder);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListVolumeTypes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.openstack.cinder.v1.CinderApi;
28 | import org.jclouds.openstack.cinder.v1.CinderApiMetadata;
29 | import org.jclouds.openstack.cinder.v1.CinderAsyncApi;
30 | import org.jclouds.openstack.cinder.v1.domain.VolumeType;
31 | import org.jclouds.rest.RestContext;
32 |
33 | /**
34 | * This example lists all volume types.
35 | *
36 | * @author Everett Toews
37 | */
38 | public class ListVolumeTypes implements Closeable {
39 | private RestContext cinder;
40 | private Set zones;
41 |
42 | /**
43 | * To get a username and API key see
44 | * http://www.jclouds.org/documentation/quickstart/rackspace/
45 | *
46 | * The first argument (args[0]) must be your username The second argument
47 | * (args[1]) must be your API key
48 | */
49 | public static void main(String[] args) {
50 | ListVolumeTypes listVolumeTypes = new ListVolumeTypes();
51 |
52 | try {
53 | listVolumeTypes.init(args);
54 | listVolumeTypes.listVolumeTypes();
55 | }
56 | catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | finally {
60 | listVolumeTypes.close();
61 | }
62 | }
63 |
64 | private void init(String[] args) {
65 | // The provider configures jclouds To use the Rackspace Cloud (US)
66 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudblockstorage-uk"
67 | String provider = "rackspace-cloudblockstorage-us";
68 |
69 | String username = args[0];
70 | String apiKey = args[1];
71 |
72 | cinder = ContextBuilder.newBuilder(provider)
73 | .credentials(username, apiKey)
74 | .build(CinderApiMetadata.CONTEXT_TOKEN);
75 | zones = cinder.getApi().getConfiguredZones();
76 | }
77 |
78 | private void listVolumeTypes() {
79 | System.out.println("List Volumes Types");
80 |
81 | for (String zone: zones) {
82 | System.out.println(" " + zone);
83 |
84 | for (VolumeType volumeType: cinder.getApi().getVolumeTypeApiForZone(zone).list()) {
85 | System.out.println(" " + volumeType);
86 | }
87 | }
88 | }
89 |
90 | /**
91 | * Always close your service when you're done with it.
92 | */
93 | public void close() {
94 | closeQuietly(cinder);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/CreateContainer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudfiles;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 |
25 | import org.jclouds.ContextBuilder;
26 | import org.jclouds.blobstore.BlobStore;
27 | import org.jclouds.blobstore.BlobStoreContext;
28 | import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
29 | import org.jclouds.openstack.swift.CommonSwiftClient;
30 | import org.jclouds.openstack.swift.options.CreateContainerOptions;
31 | import org.jclouds.rest.RestContext;
32 |
33 | import com.google.common.collect.ImmutableMap;
34 |
35 | /**
36 | * Create an object storage container with some metadata associated with it.
37 | *
38 | * @author Everett Toews
39 | */
40 | public class CreateContainer implements Closeable {
41 | private BlobStore storage;
42 | private RestContext swift;
43 |
44 | /**
45 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
46 | *
47 | * The first argument (args[0]) must be your username
48 | * The second argument (args[1]) must be your API key
49 | */
50 | public static void main(String[] args) {
51 | CreateContainer createContainer = new CreateContainer();
52 |
53 | try {
54 | createContainer.init(args);
55 | createContainer.createContainer();
56 | }
57 | finally {
58 | createContainer.close();
59 | }
60 | }
61 |
62 | private void init(String[] args) {
63 | // The provider configures jclouds To use the Rackspace Cloud (US)
64 | // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
65 | String provider = "cloudfiles-us";
66 |
67 | String username = args[0];
68 | String apiKey = args[1];
69 |
70 | BlobStoreContext context = ContextBuilder.newBuilder(provider)
71 | .credentials(username, apiKey)
72 | .buildView(BlobStoreContext.class);
73 | storage = context.getBlobStore();
74 | swift = context.unwrap();
75 | }
76 |
77 | private void createContainer() {
78 | System.out.println("Create Container");
79 |
80 | CreateContainerOptions options = CreateContainerOptions.Builder
81 | .withMetadata(ImmutableMap.of("key1", "value1", "key2", "value2"));
82 |
83 | swift.getApi().createContainer(Constants.CONTAINER, options);
84 |
85 | System.out.println(" " + Constants.CONTAINER);
86 | }
87 |
88 | /**
89 | * Always close your service when you're done with it.
90 | */
91 | public void close() {
92 | closeQuietly(storage.getContext());
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/DeleteDomains.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.examples.rackspace.clouddns.Constants.GET_DOMAIN_ID;
23 | import static org.jclouds.examples.rackspace.clouddns.Constants.IS_DOMAIN;
24 | import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete;
25 |
26 | import java.io.Closeable;
27 | import java.util.Set;
28 | import java.util.concurrent.TimeoutException;
29 |
30 | import org.jclouds.ContextBuilder;
31 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi;
32 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
33 |
34 | import com.google.common.collect.Iterables;
35 |
36 | /**
37 | * This example deletes all domains.
38 | *
39 | * @author Everett Toews
40 | */
41 | public class DeleteDomains implements Closeable {
42 | private CloudDNSApi dnsApi;
43 |
44 | /**
45 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
46 | *
47 | * The first argument (args[0]) must be your username
48 | * The second argument (args[1]) must be your API key
49 | */
50 | public static void main(String[] args) {
51 | DeleteDomains deleteDomains = new DeleteDomains();
52 |
53 | try {
54 | deleteDomains.init(args);
55 | deleteDomains.deleteAllDomains();
56 | }
57 | catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | finally {
61 | deleteDomains.close();
62 | }
63 | }
64 |
65 | private void init(String[] args) {
66 | // The provider configures jclouds To use the Rackspace Cloud (US)
67 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-clouddns-uk"
68 | String provider = "rackspace-clouddns-us";
69 |
70 | String username = args[0];
71 | String apiKey = args[1];
72 |
73 | dnsApi = ContextBuilder.newBuilder(provider)
74 | .credentials(username, apiKey)
75 | .buildApi(CloudDNSApi.class);
76 | }
77 |
78 | private void deleteAllDomains() throws TimeoutException {
79 | System.out.println("Delete Domains");
80 |
81 | Set allDomains = dnsApi.getDomainApi().list().concat().toImmutableSet();
82 | Iterable topLevelDomains = Iterables.filter(allDomains, IS_DOMAIN);
83 | Iterable topLevelDomainIds = Iterables.transform(topLevelDomains, GET_DOMAIN_ID);
84 |
85 | awaitComplete(dnsApi, dnsApi.getDomainApi().delete(topLevelDomainIds, true));
86 |
87 | System.out.println(" Deleted " + Iterables.size(topLevelDomainIds) + " top level domains and all subdomains");
88 | }
89 |
90 | /**
91 | * Always close your service when you're done with it.
92 | */
93 | public void close() {
94 | closeQuietly(dnsApi);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/blobstore-basics/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
25 | 4.0.0
26 | org.jclouds.examples
27 | blobstore-basics
28 | 1.0-SNAPSHOT
29 | blobstore-basics
30 | jclouds blobstore example that creates a container, then displays the size of each container
31 |
32 |
33 |
34 | org.jclouds
35 | jclouds-blobstore
36 | 1.6.0
37 |
38 |
39 | org.jclouds
40 | jclouds-allblobstore
41 | 1.6.0
42 |
43 |
46 |
53 |
54 |
55 | ${project.artifactId}
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-jar-plugin
61 |
62 |
63 |
64 | org.jclouds.examples.blobstore.basics.MainApp
65 |
66 |
67 |
68 |
69 |
70 |
71 | maven-assembly-plugin
72 | 2.2.1
73 |
74 |
75 | src/main/assembly/jar-with-dependencies.xml
76 |
77 |
78 |
79 | org.jclouds.examples.blobstore.basics.MainApp
80 |
81 |
82 |
83 |
84 |
85 | make-assembly
86 | package
87 |
88 | single
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/ListObjects.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudfiles;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.blobstore.BlobStore;
28 | import org.jclouds.blobstore.BlobStoreContext;
29 | import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
30 | import org.jclouds.openstack.swift.CommonSwiftClient;
31 | import org.jclouds.openstack.swift.domain.ObjectInfo;
32 | import org.jclouds.openstack.swift.options.ListContainerOptions;
33 | import org.jclouds.rest.RestContext;
34 |
35 | /**
36 | * List objects in the object storage container from the CreateContainer example.
37 | *
38 | * @author Everett Toews
39 | */
40 | public class ListObjects implements Closeable {
41 | private BlobStore storage;
42 | private RestContext swift;
43 |
44 | /**
45 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
46 | *
47 | * The first argument (args[0]) must be your username
48 | * The second argument (args[1]) must be your API key
49 | */
50 | public static void main(String[] args) {
51 | ListObjects listContainers = new ListObjects();
52 |
53 | try {
54 | listContainers.init(args);
55 | listContainers.listObjects();
56 | listContainers.listObjectsWithFiltering();
57 | }
58 | finally {
59 | listContainers.close();
60 | }
61 | }
62 |
63 | private void init(String[] args) {
64 | // The provider configures jclouds To use the Rackspace Cloud (US)
65 | // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
66 | String provider = "cloudfiles-us";
67 |
68 | String username = args[0];
69 | String apiKey = args[1];
70 |
71 | BlobStoreContext context = ContextBuilder.newBuilder(provider)
72 | .credentials(username, apiKey)
73 | .buildView(BlobStoreContext.class);
74 | storage = context.getBlobStore();
75 | swift = context.unwrap();
76 | }
77 |
78 | private void listObjects() {
79 | System.out.println("List Objects");
80 |
81 | Set objects = swift.getApi().listObjects(Constants.CONTAINER);
82 |
83 | for (ObjectInfo objectInfo: objects) {
84 | System.out.println(" " + objectInfo);
85 | }
86 | }
87 |
88 | private void listObjectsWithFiltering() {
89 | System.out.println("List Objects With Filtering");
90 |
91 | ListContainerOptions filter = ListContainerOptions.Builder.withPrefix("createObjectFromString");
92 | Set objects = swift.getApi().listObjects(Constants.CONTAINER, filter);
93 |
94 | for (ObjectInfo objectInfo: objects) {
95 | System.out.println(" " + objectInfo);
96 | }
97 | }
98 |
99 | /**
100 | * Always close your service when you're done with it.
101 | */
102 | public void close() {
103 | closeQuietly(storage.getContext());
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudservers/DeleteServer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudservers;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.compute.predicates.NodePredicates.inGroup;
23 |
24 | import java.io.Closeable;
25 | import java.util.Properties;
26 | import java.util.Set;
27 |
28 | import org.jclouds.ContextBuilder;
29 | import org.jclouds.compute.ComputeService;
30 | import org.jclouds.compute.ComputeServiceContext;
31 | import org.jclouds.compute.config.ComputeServiceProperties;
32 | import org.jclouds.compute.domain.NodeMetadata;
33 |
34 | /**
35 | * This example destroys the server created in the CreateServer example.
36 | *
37 | * @author Everett Toews
38 | */
39 | public class DeleteServer implements Closeable {
40 | private ComputeService compute;
41 |
42 | /**
43 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
44 | *
45 | * The first argument (args[0]) must be your username
46 | * The second argument (args[1]) must be your API key
47 | */
48 | public static void main(String[] args) {
49 | DeleteServer deleteServer = new DeleteServer();
50 |
51 | try {
52 | deleteServer.init(args);
53 | deleteServer.deleteServer();
54 | }
55 | finally {
56 | deleteServer.close();
57 | }
58 | }
59 |
60 | private void init(String[] args) {
61 | // The provider configures jclouds To use the Rackspace Cloud (US)
62 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
63 | String provider = "rackspace-cloudservers-us";
64 |
65 | String username = args[0];
66 | String apiKey = args[1];
67 |
68 | // These properties control how often jclouds polls for a status udpate
69 | Properties overrides = new Properties();
70 | overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD, Constants.POLL_PERIOD_TWENTY_SECONDS);
71 | overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD, Constants.POLL_PERIOD_TWENTY_SECONDS);
72 |
73 | ComputeServiceContext context = ContextBuilder.newBuilder(provider)
74 | .credentials(username, apiKey)
75 | .overrides(overrides)
76 | .buildView(ComputeServiceContext.class);
77 | compute = context.getComputeService();
78 | }
79 |
80 | /**
81 | * This will delete all servers in group {@link Constants.NAME}
82 | */
83 | private void deleteServer() {
84 | System.out.println("Delete Server");
85 |
86 | // This method will continue to poll for the server status and won't return until this server is DELETED
87 | // If you want to know what's happening during the polling, enable logging. See
88 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
89 | Set extends NodeMetadata> servers = compute.destroyNodesMatching(inGroup(Constants.NAME));
90 |
91 | for (NodeMetadata nodeMetadata: servers) {
92 | System.out.println(" " + nodeMetadata);
93 | }
94 | }
95 |
96 | /**
97 | * Always close your service when you're done with it.
98 | */
99 | public void close() {
100 | closeQuietly(compute.getContext());
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/DeleteLoadBalancers.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudloadbalancers;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.util.concurrent.TimeoutException;
24 |
25 | import org.jclouds.ContextBuilder;
26 | import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
27 | import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
28 | import org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi;
29 | import org.jclouds.rackspace.cloudloadbalancers.v1.predicates.LoadBalancerPredicates;
30 |
31 | /**
32 | * This example deletes Load Balancers.
33 | *
34 | * @author Everett Toews
35 | */
36 | public class DeleteLoadBalancers {
37 | private CloudLoadBalancersApi clb;
38 | private LoadBalancerApi lbApi;
39 |
40 | /**
41 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
42 | *
43 | * The first argument (args[0]) must be your username
44 | * The second argument (args[1]) must be your API key
45 | */
46 | public static void main(String[] args) {
47 | DeleteLoadBalancers listLoadBalancers = new DeleteLoadBalancers();
48 |
49 | try {
50 | listLoadBalancers.init(args);
51 | listLoadBalancers.deleteLoadBalancers();
52 | }
53 | catch (Exception e) {
54 | e.printStackTrace();
55 | }
56 | finally {
57 | listLoadBalancers.close();
58 | }
59 | }
60 |
61 | private void init(String[] args) {
62 | // The provider configures jclouds To use the Rackspace Cloud (US)
63 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudloadbalancers-uk"
64 | String provider = "rackspace-cloudloadbalancers-us";
65 |
66 | String username = args[0];
67 | String apiKey = args[1];
68 |
69 | clb = ContextBuilder.newBuilder(provider)
70 | .credentials(username, apiKey)
71 | .buildApi(CloudLoadBalancersApi.class);
72 | lbApi = clb.getLoadBalancerApiForZone(Constants.ZONE);
73 | }
74 |
75 | /**
76 | * This method will delete all Load Balancers starting with Constants.NAME.
77 | */
78 | private void deleteLoadBalancers() throws TimeoutException {
79 | System.out.println("Delete Load Balancers");
80 |
81 | for (LoadBalancer loadBalancer: lbApi.list().concat()) {
82 | if (loadBalancer.getName().startsWith(Constants.NAME)) {
83 | lbApi.delete(loadBalancer.getId());
84 |
85 | // Wait for the Load Balancer to be Deleted before moving on
86 | // If you want to know what's happening during the polling, enable logging. See
87 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
88 | if (!LoadBalancerPredicates.awaitDeleted(lbApi).apply(loadBalancer)) {
89 | throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer);
90 | }
91 |
92 | System.out.println(" " + loadBalancer);
93 | }
94 | }
95 | }
96 |
97 | /**
98 | * Always close your service when you're done with it.
99 | */
100 | public void close() {
101 | closeQuietly(clb);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/DeleteRecords.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.examples.rackspace.clouddns.Constants.ALT_NAME;
23 | import static org.jclouds.rackspace.clouddns.v1.functions.RecordFunctions.GET_RECORD_ID;
24 | import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete;
25 |
26 | import java.io.Closeable;
27 | import java.util.Set;
28 | import java.util.concurrent.TimeoutException;
29 |
30 | import org.jclouds.ContextBuilder;
31 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi;
32 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
33 | import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail;
34 |
35 | import com.google.common.collect.Iterables;
36 |
37 | /**
38 | * This example deletes the records on a domain.
39 | *
40 | * @author Everett Toews
41 | */
42 | public class DeleteRecords implements Closeable {
43 | private CloudDNSApi dnsApi;
44 |
45 | /**
46 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
47 | *
48 | * The first argument (args[0]) must be your username
49 | * The second argument (args[1]) must be your API key
50 | */
51 | public static void main(String[] args) {
52 | DeleteRecords deleteRecords = new DeleteRecords();
53 |
54 | try {
55 | deleteRecords.init(args);
56 | Domain domain = deleteRecords.getDomain();
57 | deleteRecords.deleteRecords(domain);
58 | }
59 | catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | finally {
63 | deleteRecords.close();
64 | }
65 | }
66 |
67 | private void init(String[] args) {
68 | // The provider configures jclouds To use the Rackspace Cloud (US)
69 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-clouddns-uk"
70 | String provider = "rackspace-clouddns-us";
71 |
72 | String username = args[0];
73 | String apiKey = args[1];
74 |
75 | dnsApi = ContextBuilder.newBuilder(provider)
76 | .credentials(username, apiKey)
77 | .buildApi(CloudDNSApi.class);
78 | }
79 |
80 | private Domain getDomain() {
81 | for (Domain domain: dnsApi.getDomainApi().list().concat()) {
82 | if (domain.getName().startsWith(ALT_NAME)) {
83 | return domain;
84 | }
85 | }
86 |
87 | throw new RuntimeException(ALT_NAME + " not found. Run CreateDomains example first.");
88 | }
89 |
90 | private void deleteRecords(Domain domain) throws TimeoutException {
91 | System.out.println("Delete Records");
92 |
93 | Set recordDetails = dnsApi.getRecordApiForDomain(domain.getId()).listByType("TXT").concat().toImmutableSet();
94 | Iterable recordIds = Iterables.transform(recordDetails, GET_RECORD_ID);
95 |
96 | awaitComplete(dnsApi, dnsApi.getRecordApiForDomain(domain.getId()).delete(recordIds));
97 |
98 | System.out.println(" Deleted " + Iterables.size(recordDetails) + " records");
99 | }
100 |
101 | /**
102 | * Always close your service when you're done with it.
103 | */
104 | public void close() {
105 | closeQuietly(dnsApi);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/ListDomains.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.examples.rackspace.clouddns.Constants.ALT_NAME;
23 | import static org.jclouds.examples.rackspace.clouddns.Constants.NAME;
24 |
25 | import java.io.Closeable;
26 |
27 | import org.jclouds.ContextBuilder;
28 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi;
29 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
30 | import org.jclouds.rackspace.clouddns.v1.domain.Subdomain;
31 |
32 | /**
33 | * This example lists domains.
34 | *
35 | * @author Everett Toews
36 | */
37 | public class ListDomains implements Closeable {
38 | private CloudDNSApi dnsApi;
39 | private int domainId;
40 |
41 | /**
42 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
43 | *
44 | * The first argument (args[0]) must be your username
45 | * The second argument (args[1]) must be your API key
46 | */
47 | public static void main(String[] args) {
48 | ListDomains listDomains = new ListDomains();
49 |
50 | try {
51 | listDomains.init(args);
52 | listDomains.listDomains();
53 | listDomains.listWithFilterByNamesMatching();
54 | listDomains.listSubdomains();
55 | }
56 | catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | finally {
60 | listDomains.close();
61 | }
62 | }
63 |
64 | private void init(String[] args) {
65 | // The provider configures jclouds To use the Rackspace Cloud (US)
66 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-clouddns-uk"
67 | String provider = "rackspace-clouddns-us";
68 |
69 | String username = args[0];
70 | String apiKey = args[1];
71 |
72 | dnsApi = ContextBuilder.newBuilder(provider)
73 | .credentials(username, apiKey)
74 | .buildApi(CloudDNSApi.class);
75 | }
76 |
77 | private void listDomains() {
78 | System.out.println("List Domains");
79 |
80 | Iterable domains = dnsApi.getDomainApi().list().concat();
81 |
82 | for (Domain domain: domains) {
83 | System.out.println(" " + domain);
84 |
85 | if (domain.getName().equals(NAME)) {
86 | domainId = domain.getId();
87 | }
88 | }
89 | }
90 |
91 | private void listWithFilterByNamesMatching() {
92 | System.out.println("List With Filter By Names Matching");
93 |
94 | Iterable domains = dnsApi.getDomainApi().listWithFilterByNamesMatching(ALT_NAME).concat();
95 |
96 | for (Domain domain: domains) {
97 | System.out.println(" " + domain);
98 | }
99 | }
100 |
101 | private void listSubdomains() {
102 | System.out.println("List Subdomains");
103 |
104 | Iterable subdomains = dnsApi.getDomainApi().listSubdomains(domainId).concat();
105 |
106 | for (Subdomain subdomain: subdomains) {
107 | System.out.println(" " + subdomain);
108 | }
109 | }
110 |
111 | /**
112 | * Always close your service when you're done with it.
113 | */
114 | public void close() {
115 | closeQuietly(dnsApi);
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/UploadLargeObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudfiles;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.blobstore.options.PutOptions.Builder.multipart;
23 |
24 | import java.io.Closeable;
25 | import java.io.File;
26 | import java.util.Properties;
27 | import java.util.concurrent.ExecutionException;
28 |
29 | import org.jclouds.ContextBuilder;
30 | import org.jclouds.blobstore.BlobStore;
31 | import org.jclouds.blobstore.BlobStoreContext;
32 | import org.jclouds.blobstore.domain.Blob;
33 |
34 | /**
35 | * Upload a large object in the object storage container from the CreateContainer example.
36 | *
37 | * @author Everett Toews
38 | */
39 | public class UploadLargeObject implements Closeable {
40 | private BlobStore storage;
41 |
42 | /**
43 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
44 | *
45 | * The first argument (args[0]) must be your username
46 | * The second argument (args[1]) must be your API key
47 | * The third argument (args[2]) must be the absolute path to a large file
48 | */
49 | public static void main(String[] args) {
50 | UploadLargeObject createContainer = new UploadLargeObject();
51 |
52 | try {
53 | createContainer.init(args);
54 | createContainer.uploadLargeObjectFromFile(new File(args[2]));
55 | }
56 | catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | finally {
60 | createContainer.close();
61 | }
62 | }
63 |
64 | private void init(String[] args) {
65 | // The provider configures jclouds To use the Rackspace Cloud (US)
66 | // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
67 | String provider = "cloudfiles-us";
68 |
69 | String username = args[0];
70 | String apiKey = args[1];
71 |
72 | Properties overrides = new Properties();
73 | // This property controls the number of parts being uploaded in parallel, the default is 4
74 | overrides.setProperty("jclouds.mpu.parallel.degree", "5");
75 | // This property controls the size (in bytes) of parts being uploaded in parallel, the default is 33554432 bytes = 32 MB
76 | overrides.setProperty("jclouds.mpu.parts.size", "67108864"); // 64 MB
77 |
78 | BlobStoreContext context = ContextBuilder.newBuilder(provider)
79 | .credentials(username, apiKey)
80 | .buildView(BlobStoreContext.class);
81 | storage = context.getBlobStore();
82 | }
83 |
84 | /**
85 | * Upload a large object from a File using the Swift API.
86 | * @throws ExecutionException
87 | * @throws InterruptedException
88 | */
89 | private void uploadLargeObjectFromFile(File largeFile) throws InterruptedException, ExecutionException {
90 | System.out.println("Upload Large Object From File");
91 |
92 | Blob blob = storage.blobBuilder(largeFile.getName())
93 | .payload(largeFile)
94 | .build();
95 |
96 | String eTag = storage.putBlob(Constants.CONTAINER, blob, multipart());
97 |
98 | System.out.println(" Uploaded " + largeFile.getName() + " eTag=" + eTag);
99 | }
100 |
101 | /**
102 | * Always close your service when you're done with it.
103 | */
104 | public void close() {
105 | closeQuietly(storage.getContext());
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/DeleteObjectsAndContainer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudfiles;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.blobstore.BlobStore;
28 | import org.jclouds.blobstore.BlobStoreContext;
29 | import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
30 | import org.jclouds.openstack.swift.CommonSwiftClient;
31 | import org.jclouds.openstack.swift.domain.ContainerMetadata;
32 | import org.jclouds.openstack.swift.domain.ObjectInfo;
33 | import org.jclouds.openstack.swift.options.ListContainerOptions;
34 | import org.jclouds.rest.RestContext;
35 |
36 | /**
37 | * Delete the objects from the CreateObjects example and delete the object storage container from the
38 | * CreateContainer example.
39 | *
40 | * @author Everett Toews
41 | */
42 | public class DeleteObjectsAndContainer implements Closeable {
43 | private BlobStore storage;
44 | private RestContext swift;
45 |
46 | /**
47 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
48 | *
49 | * The first argument (args[0]) must be your username
50 | * The second argument (args[1]) must be your API key
51 | */
52 | public static void main(String[] args) {
53 | DeleteObjectsAndContainer deleteObjectsAndContainer = new DeleteObjectsAndContainer();
54 |
55 | try {
56 | deleteObjectsAndContainer.init(args);
57 | deleteObjectsAndContainer.deleteObjectsAndContainer();
58 | }
59 | finally {
60 | deleteObjectsAndContainer.close();
61 | }
62 | }
63 |
64 | private void init(String[] args) {
65 | // The provider configures jclouds To use the Rackspace Cloud (US)
66 | // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
67 | String provider = "cloudfiles-us";
68 |
69 | String username = args[0];
70 | String apiKey = args[1];
71 |
72 | BlobStoreContext context = ContextBuilder.newBuilder(provider)
73 | .credentials(username, apiKey)
74 | .buildView(BlobStoreContext.class);
75 | storage = context.getBlobStore();
76 | swift = context.unwrap();
77 | }
78 |
79 | /**
80 | * This will delete all containers that start with {@link CONTAINER} and the objects within those containers.
81 | */
82 | private void deleteObjectsAndContainer() {
83 | System.out.println("Delete Container");
84 |
85 | Set containers = swift.getApi()
86 | .listContainers(ListContainerOptions.Builder.withPrefix(Constants.CONTAINER));
87 |
88 | for (ContainerMetadata container: containers) {
89 | System.out.println(" " + container.getName());
90 |
91 | Set objects = swift.getApi().listObjects(container.getName());
92 |
93 | for (ObjectInfo object: objects) {
94 | System.out.println(" " + object.getName());
95 |
96 | swift.getApi().removeObject(container.getName(), object.getName());
97 | }
98 |
99 | swift.getApi().deleteContainerIfEmpty(container.getName());
100 | }
101 | }
102 |
103 | /**
104 | * Always close your service when you're done with it.
105 | */
106 | public void close() {
107 | closeQuietly(storage.getContext());
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/CreateRecords.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.examples.rackspace.clouddns.Constants.ALT_NAME;
23 | import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete;
24 |
25 | import java.io.Closeable;
26 | import java.util.Set;
27 | import java.util.concurrent.TimeoutException;
28 |
29 | import org.jclouds.ContextBuilder;
30 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi;
31 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
32 | import org.jclouds.rackspace.clouddns.v1.domain.Record;
33 | import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail;
34 |
35 | import com.google.common.collect.ImmutableSet;
36 |
37 | /**
38 | * This example creates records on an existing domain.
39 | *
40 | * @author Everett Toews
41 | */
42 | public class CreateRecords implements Closeable {
43 | private CloudDNSApi dnsApi;
44 |
45 | /**
46 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
47 | *
48 | * The first argument (args[0]) must be your username
49 | * The second argument (args[1]) must be your API key
50 | */
51 | public static void main(String[] args) {
52 | CreateRecords createRecords = new CreateRecords();
53 |
54 | try {
55 | createRecords.init(args);
56 | createRecords.createRecords();
57 | }
58 | catch (Exception e) {
59 | e.printStackTrace();
60 | }
61 | finally {
62 | createRecords.close();
63 | }
64 | }
65 |
66 | private void init(String[] args) {
67 | // The provider configures jclouds To use the Rackspace Cloud (US)
68 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-clouddns-uk"
69 | String provider = "rackspace-clouddns-us";
70 |
71 | String username = args[0];
72 | String apiKey = args[1];
73 |
74 | dnsApi = ContextBuilder.newBuilder(provider)
75 | .credentials(username, apiKey)
76 | .buildApi(CloudDNSApi.class);
77 | }
78 |
79 | private void createRecords() throws TimeoutException {
80 | System.out.println("Create Records");
81 |
82 | int domainId = 0;
83 |
84 | Iterable domains = dnsApi.getDomainApi().list().concat();
85 |
86 | for (Domain domain: domains) {
87 | if (domain.getName().equals(ALT_NAME)) {
88 | domainId = domain.getId();
89 | }
90 | }
91 |
92 | Record createTXTRecord = Record.builder()
93 | .name(ALT_NAME)
94 | .type("TXT")
95 | .data("This is a TXT record")
96 | .build();
97 |
98 | Record createARecord = Record.builder()
99 | .name(ALT_NAME)
100 | .type("A")
101 | .data("10.0.0.2")
102 | .build();
103 |
104 | Set createRecords = ImmutableSet.of(createTXTRecord, createARecord);
105 |
106 | Set recordDetails = awaitComplete(dnsApi, dnsApi.getRecordApiForDomain(domainId).create(createRecords));
107 |
108 | for (RecordDetail recordDetail: recordDetails) {
109 | System.out.println(" " + recordDetail);
110 | }
111 | }
112 |
113 | /**
114 | * Always close your service when you're done with it.
115 | */
116 | public void close() {
117 | closeQuietly(dnsApi);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.compute.ComputeService;
28 | import org.jclouds.compute.ComputeServiceContext;
29 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
30 | import org.jclouds.openstack.nova.v2_0.NovaApi;
31 | import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
32 | import org.jclouds.rest.RestContext;
33 |
34 | import com.google.common.collect.ImmutableSet;
35 | import com.google.inject.Module;
36 |
37 | /**
38 | * This example shows you how to log what jclouds is doing. This is extremely useful for debugging, submitting bug
39 | * reports, getting help, and figuring exactly what the HTTP requests and resonses look like.
40 | *
41 | * In this example we use the Simple Logging Facade for Java (SLF4J). The implementation of SLF4J that we'll use is
42 | * Logback so you'll need to download the Logback JARs from http://logback.qos.ch/download.html and put them on your
43 | * classpath.
44 | *
45 | * The last key ingredient is the file /jclouds-examples/rackspace/src/main/resources/logback.xml which configures
46 | * the logging. As it is configured right now it will log wire input/output and headers to standard out (STDOUT).
47 | * This means that you will be able to see on your console everything that is sent in the request (marked by ">>")
48 | * and everything received in the response (marked by "<<").
49 | *
50 | * @author Everett Toews
51 | */
52 | public class Logging implements Closeable {
53 | private ComputeService compute;
54 | private RestContext nova;
55 | private Set zones;
56 |
57 | /**
58 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
59 | *
60 | * The first argument (args[0]) must be your username
61 | * The second argument (args[1]) must be your API key
62 | */
63 | public static void main(String[] args) {
64 | Logging logging = new Logging();
65 |
66 | try {
67 | logging.init(args);
68 | }
69 | finally {
70 | logging.close();
71 | }
72 | }
73 |
74 | private void init(String[] args) {
75 | // The provider configures jclouds To use the Rackspace Cloud (US)
76 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
77 | String provider = "rackspace-cloudservers-us";
78 |
79 | String username = args[0];
80 | String apiKey = args[1];
81 |
82 | // This module is responsible for enabling logging
83 | Iterable modules = ImmutableSet. of(new SLF4JLoggingModule());
84 |
85 | ComputeServiceContext context = ContextBuilder.newBuilder(provider)
86 | .credentials(username, apiKey)
87 | .modules(modules) // don't forget to add the modules to your context!
88 | .buildView(ComputeServiceContext.class);
89 | compute = context.getComputeService();
90 | nova = context.unwrap();
91 |
92 | // Calling getConfiguredZones() talks to the cloud which gets logged
93 | zones = nova.getApi().getConfiguredZones();
94 | System.out.println("Zones: " + zones);
95 | }
96 |
97 | /**
98 | * Always close your service when you're done with it.
99 | */
100 | public void close() {
101 | closeQuietly(compute.getContext());
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/DeleteVolume.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.concurrent.TimeoutException;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.openstack.cinder.v1.CinderApi;
28 | import org.jclouds.openstack.cinder.v1.CinderApiMetadata;
29 | import org.jclouds.openstack.cinder.v1.CinderAsyncApi;
30 | import org.jclouds.openstack.cinder.v1.domain.Volume;
31 | import org.jclouds.openstack.cinder.v1.features.VolumeApi;
32 | import org.jclouds.openstack.cinder.v1.predicates.VolumePredicates;
33 | import org.jclouds.rest.RestContext;
34 |
35 | /**
36 | * This example deletes a volume.
37 | *
38 | * @author Everett Toews
39 | */
40 | public class DeleteVolume implements Closeable {
41 | private RestContext cinder;
42 | private VolumeApi volumeApi;
43 |
44 | /**
45 | * To get a username and API key see
46 | * http://www.jclouds.org/documentation/quickstart/rackspace/
47 | *
48 | * The first argument (args[0]) must be your username The second argument
49 | * (args[1]) must be your API key
50 | */
51 | public static void main(String[] args) {
52 | DeleteVolume deleteVolume = new DeleteVolume();
53 |
54 | try {
55 | deleteVolume.init(args);
56 | Volume volume = deleteVolume.getVolume();
57 | deleteVolume.deleteVolume(volume);
58 | }
59 | catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | finally {
63 | deleteVolume.close();
64 | }
65 | }
66 |
67 | private void init(String[] args) {
68 | // The provider configures jclouds To use the Rackspace Cloud (US)
69 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudblockstorage-uk"
70 | String provider = "rackspace-cloudblockstorage-us";
71 |
72 | String username = args[0];
73 | String apiKey = args[1];
74 |
75 | cinder = ContextBuilder.newBuilder(provider)
76 | .credentials(username, apiKey)
77 | .build(CinderApiMetadata.CONTEXT_TOKEN);
78 | volumeApi = cinder.getApi().getVolumeApiForZone(Constants.ZONE);
79 | }
80 |
81 | /**
82 | * @return Volume The Volume created in the CreateVolumeAndAttach example
83 | */
84 | private Volume getVolume() {
85 | for (Volume volume: volumeApi.list()) {
86 | if (volume.getName().startsWith(Constants.NAME)) {
87 | return volume;
88 | }
89 | }
90 |
91 | throw new RuntimeException(Constants.NAME + " not found. Run the CreateVolumeAndAttach example first.");
92 | }
93 |
94 | private void deleteVolume(Volume volume) throws TimeoutException {
95 | System.out.println("Delete Volume");
96 |
97 | boolean result = volumeApi.delete(volume.getId());
98 |
99 | // Wait for the volume to be deleted before moving on
100 | // If you want to know what's happening during the polling, enable
101 | // logging. See /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
102 | if (!VolumePredicates.awaitDeleted(volumeApi).apply(volume)) {
103 | throw new TimeoutException("Timeout on volume: " + volume);
104 | }
105 |
106 | System.out.println(" " + result);
107 | }
108 |
109 | /**
110 | * Always close your service when you're done with it.
111 | */
112 | public void close() {
113 | closeQuietly(cinder);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/minecraft-compute/src/main/java/org/jclouds/examples/minecraft/MinecraftController.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.jclouds.examples.minecraft;
21 |
22 | import static com.google.common.base.Objects.toStringHelper;
23 | import static com.google.common.collect.Iterables.transform;
24 | import static com.google.common.io.Closeables.closeQuietly;
25 | import static org.jclouds.examples.minecraft.Utils.firstPublicAddressToHostAndPort;
26 | import static org.jclouds.util.Maps2.transformKeys;
27 |
28 | import java.io.Closeable;
29 | import java.util.Map;
30 | import java.util.Set;
31 |
32 | import javax.annotation.Resource;
33 | import javax.inject.Inject;
34 | import javax.inject.Named;
35 | import javax.inject.Provider;
36 | import javax.inject.Singleton;
37 |
38 | import org.jclouds.compute.domain.NodeMetadata;
39 | import org.jclouds.lifecycle.Closer;
40 | import org.jclouds.logging.Logger;
41 | import org.jclouds.scriptbuilder.InitScript;
42 |
43 | import com.google.common.net.HostAndPort;
44 |
45 | /**
46 | * @author Adrian Cole
47 | */
48 | @Singleton
49 | public class MinecraftController implements Closeable {
50 |
51 | @Resource
52 | protected Logger logger = Logger.NULL;
53 |
54 | private final Closer closer;
55 | private final NodeManager nodeManager;
56 | private final Provider daemonFactory;
57 | private final int port;
58 | private final String group;
59 | private final int maxHeap;
60 |
61 | @Inject
62 | MinecraftController(Closer closer, NodeManager nodeManager, Provider daemonFactory,
63 | @Named("minecraft.port") int port, @Named("minecraft.group") String group, @Named("minecraft.mx") int maxHeap) {
64 | this.closer = closer;
65 | this.nodeManager = nodeManager;
66 | this.daemonFactory = daemonFactory;
67 | this.port = port;
68 | this.group = group;
69 | this.maxHeap = maxHeap;
70 | }
71 |
72 | public Iterable list() {
73 | return transformToHostAndPort(nodeManager.listRunningNodesInGroup(group));
74 | }
75 |
76 | public Iterable transformToHostAndPort(Set extends NodeMetadata> nodes) {
77 | return transform(nodes, firstPublicAddressToHostAndPort(port));
78 | }
79 |
80 | public HostAndPort add() {
81 | return firstPublicAddressToHostAndPort(port).apply(createNodeWithMinecraft());
82 | }
83 |
84 | private NodeMetadata createNodeWithMinecraft() {
85 | int javaPlusOverhead = maxHeap + 256;
86 | NodeMetadata node = nodeManager.createNodeWithAdminUserAndJDKInGroupOpeningPortAndMinRam(group, port,
87 | javaPlusOverhead);
88 | nodeManager.startDaemonOnNode(daemonFactory.get(), node.getId());
89 | return node;
90 | }
91 |
92 | public Map tail() {
93 | return mapHostAndPortToStdoutForCommand("/tmp/init-minecraft tail");
94 | }
95 |
96 | public Map mapHostAndPortToStdoutForCommand(String cmd) {
97 | return transformKeys(nodeManager.stdoutFromCommandOnGroup(cmd, group), firstPublicAddressToHostAndPort(port));
98 | }
99 |
100 | public Map pids() {
101 | return mapHostAndPortToStdoutForCommand("/tmp/init-minecraft status");
102 | }
103 |
104 | public Iterable destroy() {
105 | return transformToHostAndPort(nodeManager.destroyNodesInGroup(group));
106 | }
107 |
108 | @Override
109 | public void close() {
110 | closeQuietly(closer);
111 | }
112 |
113 | @Override
114 | public String toString() {
115 | return toStringHelper("").add("nodeManager", nodeManager).add("group", group).add("port", port).toString();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/DeleteSnapshot.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.concurrent.TimeoutException;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.openstack.cinder.v1.CinderApi;
28 | import org.jclouds.openstack.cinder.v1.CinderApiMetadata;
29 | import org.jclouds.openstack.cinder.v1.CinderAsyncApi;
30 | import org.jclouds.openstack.cinder.v1.domain.Snapshot;
31 | import org.jclouds.openstack.cinder.v1.features.SnapshotApi;
32 | import org.jclouds.openstack.cinder.v1.predicates.SnapshotPredicates;
33 | import org.jclouds.rest.RestContext;
34 |
35 | /**
36 | * This example deletes a snapshot.
37 | *
38 | * @author Everett Toews
39 | */
40 | public class DeleteSnapshot implements Closeable {
41 | private RestContext cinder;
42 | private SnapshotApi snapshotApi;
43 |
44 | /**
45 | * To get a username and API key see
46 | * http://www.jclouds.org/documentation/quickstart/rackspace/
47 | *
48 | * The first argument (args[0]) must be your username The second argument
49 | * (args[1]) must be your API key
50 | */
51 | public static void main(String[] args) {
52 | DeleteSnapshot deleteSnapshot = new DeleteSnapshot();
53 |
54 | try {
55 | deleteSnapshot.init(args);
56 | Snapshot snapshot = deleteSnapshot.getSnapshot();
57 | deleteSnapshot.deleteSnapshot(snapshot);
58 | }
59 | catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | finally {
63 | deleteSnapshot.close();
64 | }
65 | }
66 |
67 | private void init(String[] args) {
68 | // The provider configures jclouds To use the Rackspace Cloud (US)
69 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudblockstorage-uk"
70 | String provider = "rackspace-cloudblockstorage-us";
71 |
72 | String username = args[0];
73 | String apiKey = args[1];
74 |
75 | cinder = ContextBuilder.newBuilder(provider)
76 | .credentials(username, apiKey)
77 | .build(CinderApiMetadata.CONTEXT_TOKEN);
78 | snapshotApi = cinder.getApi().getSnapshotApiForZone(Constants.ZONE);
79 | }
80 |
81 | /**
82 | * @return Snapshot The Snapshot created in the CreateSnapshot example
83 | */
84 | private Snapshot getSnapshot() {
85 | for (Snapshot snapshot : snapshotApi.list()) {
86 | if (snapshot.getName().startsWith(Constants.NAME)) {
87 | return snapshot;
88 | }
89 | }
90 |
91 | throw new RuntimeException(Constants.NAME + " not found. Run the CreateSnapshot example first.");
92 | }
93 |
94 | private void deleteSnapshot(Snapshot snapshot) throws TimeoutException {
95 | System.out.println("Delete Snapshot");
96 |
97 | boolean result = snapshotApi.delete(snapshot.getId());
98 |
99 | // Wait for the snapshot to be deleted before moving on
100 | // If you want to know what's happening during the polling, enable logging.
101 | // See /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
102 | if (!SnapshotPredicates.awaitDeleted(snapshotApi).apply(snapshot)) {
103 | throw new TimeoutException("Timeout on snapshot: " + snapshot);
104 | }
105 |
106 | System.out.println(" " + result);
107 | }
108 |
109 | /**
110 | * Always close your service when you're done with it.
111 | */
112 | public void close() {
113 | closeQuietly(cinder);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/ListRecords.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.examples.rackspace.clouddns.Constants.NAME;
23 |
24 | import java.io.Closeable;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi;
28 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
29 | import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail;
30 |
31 | /**
32 | * This example lists records.
33 | *
34 | * @author Everett Toews
35 | */
36 | public class ListRecords implements Closeable {
37 | private CloudDNSApi dnsApi;
38 |
39 | /**
40 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
41 | *
42 | * The first argument (args[0]) must be your username
43 | * The second argument (args[1]) must be your API key
44 | */
45 | public static void main(String[] args) {
46 | ListRecords listRecords = new ListRecords();
47 |
48 | try {
49 | listRecords.init(args);
50 | Domain domain = listRecords.getDomain();
51 | listRecords.listRecords(domain);
52 | listRecords.listRecordsByNameAndType(domain);
53 | listRecords.listRecordsByType(domain);
54 | }
55 | catch (Exception e) {
56 | e.printStackTrace();
57 | }
58 | finally {
59 | listRecords.close();
60 | }
61 | }
62 |
63 | private void init(String[] args) {
64 | // The provider configures jclouds To use the Rackspace Cloud (US)
65 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-clouddns-uk"
66 | String provider = "rackspace-clouddns-us";
67 |
68 | String username = args[0];
69 | String apiKey = args[1];
70 |
71 | dnsApi = ContextBuilder.newBuilder(provider)
72 | .credentials(username, apiKey)
73 | .buildApi(CloudDNSApi.class);
74 | }
75 |
76 | private Domain getDomain() {
77 | for (Domain domain: dnsApi.getDomainApi().list().concat()) {
78 | if (domain.getName().startsWith(NAME)) {
79 | return domain;
80 | }
81 | }
82 |
83 | throw new RuntimeException(NAME + " not found. Run CreateDomains example first.");
84 | }
85 |
86 | private void listRecords(Domain domain) {
87 | System.out.println("List Records");
88 |
89 | Iterable recordDetails = dnsApi.getRecordApiForDomain(domain.getId()).list().concat();
90 |
91 | for (RecordDetail recordDetail: recordDetails) {
92 | System.out.println(" " + recordDetail);
93 | }
94 | }
95 |
96 | private void listRecordsByNameAndType(Domain domain) {
97 | System.out.println("List Records by Name and Type");
98 |
99 | Iterable recordDetails = dnsApi.getRecordApiForDomain(domain.getId()).listByNameAndType(NAME, "A").concat();
100 |
101 | for (RecordDetail recordDetail: recordDetails) {
102 | System.out.println(" " + recordDetail);
103 | }
104 | }
105 |
106 | private void listRecordsByType(Domain domain) {
107 | System.out.println("List Records by Type");
108 |
109 | Iterable recordDetails = dnsApi.getRecordApiForDomain(domain.getId()).listByType("MX").concat();
110 |
111 | for (RecordDetail recordDetail: recordDetails) {
112 | System.out.println(" " + recordDetail);
113 | }
114 | }
115 |
116 | /**
117 | * Always close your service when you're done with it.
118 | */
119 | public void close() {
120 | closeQuietly(dnsApi);
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/ec2-windows/src/main/java/org/jclouds/examples/ec2/windows/MainApp.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.jclouds.examples.ec2.windows;
21 |
22 | import com.google.common.base.Function;
23 | import com.google.common.collect.ImmutableSet;
24 | import com.google.common.collect.Iterables;
25 | import com.google.common.collect.Sets;
26 | import com.google.inject.Module;
27 | import org.jclouds.ContextBuilder;
28 | import org.jclouds.aws.ec2.reference.AWSEC2Constants;
29 | import org.jclouds.compute.ComputeService;
30 | import org.jclouds.compute.ComputeServiceContext;
31 | import org.jclouds.domain.Location;
32 | import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
33 | import org.jclouds.location.predicates.LocationPredicates;
34 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
35 | import org.kohsuke.args4j.CmdLineException;
36 | import org.kohsuke.args4j.CmdLineParser;
37 |
38 | import javax.annotation.Nullable;
39 | import java.util.Properties;
40 | import java.util.Set;
41 |
42 | /**
43 | * The main application. This will parse and validate the command line
44 | * arguments, initialize a jclouds context, and then jump to {@link
45 | * WindowsInstanceStarter}.
46 | *
47 | * @author Richard Downer
48 | */
49 | public class MainApp {
50 |
51 | private ComputeServiceContext context;
52 | private ComputeService computeService;
53 | private Arguments arguments;
54 |
55 | public MainApp(Arguments arguments) {
56 | this.arguments = arguments;
57 | }
58 |
59 | public static void main(String[] args) throws Exception {
60 | Arguments arguments = new Arguments();
61 | CmdLineParser parser = new CmdLineParser(arguments);
62 | try {
63 | parser.parseArgument(args);
64 | } catch (CmdLineException e) {
65 | // handling of wrong arguments
66 | System.err.println(e.getMessage());
67 | parser.printUsage(System.err);
68 | System.exit(1);
69 | }
70 | new MainApp(arguments).run();
71 | }
72 |
73 | private void run() throws Exception {
74 | Properties overrides = new Properties();
75 | overrides.put(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, "owner-id=" + arguments.getAmiOwner() + ";state=available;image-type=machine");
76 |
77 | ImmutableSet modules = ImmutableSet.of(
78 | new SLF4JLoggingModule(), // OverThere uses SLF4J so we will as well
79 | new BouncyCastleCryptoModule() // needed to decrypt the password from EC2
80 | );
81 | context = ContextBuilder.newBuilder("aws-ec2")
82 | .credentials(arguments.getIdentity(), arguments.getCredential())
83 | .overrides(overrides)
84 | .modules(modules)
85 | .build(ComputeServiceContext.class);
86 |
87 | try {
88 | computeService = context.getComputeService();
89 | Set regions = Sets.newHashSet(Iterables.transform(Iterables.filter(computeService.listAssignableLocations(), LocationPredicates.isRegion()), new Function() {
90 | @Override
91 | public String apply(@Nullable Location location) {
92 | return (location != null) ? location.getId() : null;
93 | }
94 | }));
95 |
96 | if (!regions.contains(arguments.getRegion())) {
97 | System.err.println("Region \"" + arguments.getRegion() + "\" is not known. Known regions are:");
98 | for (String r : regions) {
99 | System.err.println(" " + r);
100 | }
101 | System.exit(1);
102 | }
103 |
104 | WindowsInstanceStarter app = new WindowsInstanceStarter(arguments, context);
105 | app.run();
106 | } finally {
107 | context.close();
108 | }
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudservers/ListServersWithFiltering.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudservers;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Set;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.compute.ComputeService;
28 | import org.jclouds.compute.ComputeServiceContext;
29 | import org.jclouds.compute.domain.ComputeMetadata;
30 | import org.jclouds.compute.domain.NodeMetadata;
31 | import org.jclouds.compute.predicates.NodePredicates;
32 |
33 | import com.google.common.base.Preconditions;
34 | import com.google.common.base.Predicate;
35 |
36 | /**
37 | * This example lists servers filtered by Predicates. Run the CreateServer example before this to get some results.
38 | *
39 | * @author Everett Toews
40 | */
41 | public class ListServersWithFiltering implements Closeable {
42 | private ComputeService compute;
43 |
44 | /**
45 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
46 | *
47 | * The first argument (args[0]) must be your username
48 | * The second argument (args[1]) must be your API key
49 | */
50 | public static void main(String[] args) {
51 | ListServersWithFiltering listServersWithFiltering = new ListServersWithFiltering();
52 |
53 | try {
54 | listServersWithFiltering.init(args);
55 | listServersWithFiltering.listServersByParentLocationId();
56 | listServersWithFiltering.listServersByNameStartsWith();
57 | }
58 | finally {
59 | listServersWithFiltering.close();
60 | }
61 | }
62 |
63 | private void init(String[] args) {
64 | // The provider configures jclouds To use the Rackspace Cloud (US)
65 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
66 | String provider = "rackspace-cloudservers-us";
67 |
68 | String username = args[0];
69 | String apiKey = args[1];
70 |
71 | ComputeServiceContext context = ContextBuilder.newBuilder(provider)
72 | .credentials(username, apiKey)
73 | .buildView(ComputeServiceContext.class);
74 | compute = context.getComputeService();
75 | }
76 |
77 | private void listServersByParentLocationId() {
78 | System.out.println("List Servers By Parent Location Id");
79 |
80 | Set extends NodeMetadata> servers = compute.listNodesDetailsMatching(NodePredicates
81 | .parentLocationId(Constants.ZONE));
82 |
83 | for (NodeMetadata nodeMetadata: servers) {
84 | System.out.println(" " + nodeMetadata);
85 | }
86 | }
87 |
88 | private void listServersByNameStartsWith() {
89 | System.out.println("List Servers By Name Starts With");
90 |
91 | Set extends NodeMetadata> servers = compute.listNodesDetailsMatching(nameStartsWith("jclouds-ex"));
92 |
93 | for (NodeMetadata nodeMetadata: servers) {
94 | System.out.println(" " + nodeMetadata);
95 | }
96 | }
97 |
98 | /**
99 | * Always close your service when you're done with it.
100 | */
101 | public void close() {
102 | closeQuietly(compute.getContext());
103 | }
104 |
105 | public static Predicate nameStartsWith(final String prefix) {
106 | Preconditions.checkNotNull(prefix, "prefix must be defined");
107 |
108 | return new Predicate() {
109 | @Override
110 | public boolean apply(ComputeMetadata computeMetadata) {
111 | return computeMetadata.getName().startsWith(prefix);
112 | }
113 |
114 | @Override
115 | public String toString() {
116 | return "nameStartsWith(" + prefix + ")";
117 | }
118 | };
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/UpdateDomains.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.clouddns;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 | import static org.jclouds.examples.rackspace.clouddns.Constants.ALT_NAME;
23 | import static org.jclouds.examples.rackspace.clouddns.Constants.GET_DOMAIN_ID;
24 | import static org.jclouds.examples.rackspace.clouddns.Constants.NAME;
25 | import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete;
26 |
27 | import java.io.Closeable;
28 | import java.util.concurrent.TimeoutException;
29 |
30 | import org.jclouds.ContextBuilder;
31 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi;
32 | import org.jclouds.rackspace.clouddns.v1.domain.Domain;
33 | import org.jclouds.rackspace.clouddns.v1.domain.UpdateDomain;
34 |
35 | import com.google.common.collect.Iterables;
36 |
37 | /**
38 | * This example updates a domain.
39 | *
40 | * @author Everett Toews
41 | */
42 | public class UpdateDomains implements Closeable {
43 | private CloudDNSApi dnsApi;
44 |
45 | /**
46 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
47 | *
48 | * The first argument (args[0]) must be your username
49 | * The second argument (args[1]) must be your API key
50 | */
51 | public static void main(String[] args) {
52 | UpdateDomains updateDomains = new UpdateDomains();
53 |
54 | try {
55 | updateDomains.init(args);
56 | updateDomains.updateDomain();
57 | updateDomains.updateDomains();
58 | }
59 | catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | finally {
63 | updateDomains.close();
64 | }
65 | }
66 |
67 | private void init(String[] args) {
68 | // The provider configures jclouds To use the Rackspace Cloud (US)
69 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-clouddns-uk"
70 | String provider = "rackspace-clouddns-us";
71 |
72 | String username = args[0];
73 | String apiKey = args[1];
74 |
75 | dnsApi = ContextBuilder.newBuilder(provider)
76 | .credentials(username, apiKey)
77 | .buildApi(CloudDNSApi.class);
78 | }
79 |
80 | private void updateDomain() throws TimeoutException {
81 | System.out.println("Update Domain");
82 |
83 | int domainId = 0;
84 |
85 | Iterable domains = dnsApi.getDomainApi().list().concat();
86 |
87 | for (Domain domain: domains) {
88 | if (domain.getName().equals(ALT_NAME)) {
89 | domainId = domain.getId();
90 | }
91 | }
92 |
93 | UpdateDomain updateDomain = UpdateDomain.builder()
94 | .email("jcloudie@" + ALT_NAME)
95 | .ttl(600001)
96 | .comment("Hello Domain Update")
97 | .build();
98 |
99 | awaitComplete(dnsApi, dnsApi.getDomainApi().update(domainId, updateDomain));
100 |
101 | System.out.println(" " + dnsApi.getDomainApi().get(domainId));
102 | }
103 |
104 | private void updateDomains() throws TimeoutException {
105 | System.out.println("Update Domains");
106 |
107 | Iterable domains = dnsApi.getDomainApi().list().concat();
108 | Iterable domainIds = Iterables.transform(domains, GET_DOMAIN_ID);
109 |
110 | awaitComplete(dnsApi, dnsApi.getDomainApi().updateEmail(domainIds, "jclouder@" + NAME));
111 |
112 | domains = dnsApi.getDomainApi().list().concat();
113 |
114 | for (Domain domain: domains) {
115 | System.out.println(" " + domain);
116 | }
117 | }
118 |
119 | /**
120 | * Always close your service when you're done with it.
121 | */
122 | public void close() {
123 | closeQuietly(dnsApi);
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/blobstore-largeblob/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
24 | 4.0.0
25 | org.jclouds.examples
26 | blobstore-largeblob
27 | 1.0-SNAPSHOT
28 | blobstore-largeblob
29 | jclouds blobstore example that creates a container, then uploads a large file using parallel multipart upload
30 |
31 |
32 |
33 | org.jclouds
34 | jclouds-blobstore
35 | 1.5.0-beta.3
36 |
37 |
38 | org.jclouds
39 | jclouds-allblobstore
40 | 1.5.0-beta.3
41 |
42 |
43 | org.jclouds.driver
44 | jclouds-netty
45 | 1.5.0-beta.3
46 |
47 |
48 | org.jclouds.driver
49 | jclouds-apachehc
50 | 1.5.0-beta.3
51 |
52 |
53 | org.jclouds.driver
54 | jclouds-log4j
55 | 1.5.0-beta.3
56 |
57 |
58 | org.jclouds.driver
59 | jclouds-slf4j
60 | 1.5.0-beta.3
61 |
62 |
65 |
72 |
73 |
74 | ${project.artifactId}
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-jar-plugin
80 |
81 |
82 |
83 | org.jclouds.examples.blobstore.largeblob.MainApp
84 |
85 |
86 |
87 |
88 |
89 |
90 | maven-assembly-plugin
91 |
92 |
93 | jar-with-dependencies
94 |
95 |
96 |
97 | org.jclouds.examples.blobstore.largeblob.MainApp
98 |
99 |
100 |
101 |
102 |
103 | make-assembly
104 | package
105 |
106 | single
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListVolumeAttachments.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 |
25 | import org.jclouds.ContextBuilder;
26 | import org.jclouds.compute.ComputeService;
27 | import org.jclouds.compute.ComputeServiceContext;
28 | import org.jclouds.openstack.nova.v2_0.NovaApi;
29 | import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
30 | import org.jclouds.openstack.nova.v2_0.domain.Server;
31 | import org.jclouds.openstack.nova.v2_0.domain.VolumeAttachment;
32 | import org.jclouds.openstack.nova.v2_0.extensions.VolumeAttachmentApi;
33 | import org.jclouds.openstack.nova.v2_0.features.ServerApi;
34 | import org.jclouds.rest.RestContext;
35 |
36 | import com.google.common.collect.FluentIterable;
37 |
38 | /**
39 | * This example lists the volume attachments of a server.
40 | *
41 | * @author Everett Toews
42 | */
43 | public class ListVolumeAttachments implements Closeable {
44 | private ComputeService compute;
45 | private RestContext nova;
46 | private ServerApi serverApi;
47 | private VolumeAttachmentApi volumeAttachmentApi;
48 |
49 | /**
50 | * To get a username and API key see
51 | * http://www.jclouds.org/documentation/quickstart/rackspace/
52 | *
53 | * The first argument (args[0]) must be your username The second argument
54 | * (args[1]) must be your API key
55 | */
56 | public static void main(String[] args) {
57 | ListVolumeAttachments listVolumeAttachments = new ListVolumeAttachments();
58 |
59 | try {
60 | listVolumeAttachments.init(args);
61 | Server server = listVolumeAttachments.getServer();
62 | listVolumeAttachments.listVolumeAttachments(server);
63 | }
64 | catch (Exception e) {
65 | e.printStackTrace();
66 | }
67 | finally {
68 | listVolumeAttachments.close();
69 | }
70 | }
71 |
72 | private void init(String[] args) {
73 | // The provider configures jclouds To use the Rackspace Cloud (US)
74 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
75 | String provider = "rackspace-cloudservers-us";
76 |
77 | String username = args[0];
78 | String apiKey = args[1];
79 |
80 | ComputeServiceContext context = ContextBuilder.newBuilder(provider)
81 | .credentials(username, apiKey)
82 | .buildView(ComputeServiceContext.class);
83 | compute = context.getComputeService();
84 | nova = context.unwrap();
85 | volumeAttachmentApi = nova.getApi().getVolumeAttachmentExtensionForZone(Constants.ZONE).get();
86 | serverApi = nova.getApi().getServerApiForZone(Constants.ZONE);
87 | }
88 |
89 | /**
90 | * @return Server The Server created in the CreateVolumeAndAttach example
91 | */
92 | private Server getServer() {
93 | FluentIterable extends Server> servers = serverApi.listInDetail().concat();
94 |
95 | for (Server server: servers) {
96 | if (server.getName().startsWith(Constants.NAME)) {
97 | return server;
98 | }
99 | }
100 |
101 | throw new RuntimeException(Constants.NAME + " not found. Run the CreateVolumeAndAttach example first.");
102 | }
103 |
104 | private void listVolumeAttachments(Server server) {
105 | System.out.println("List Volume Attachments");
106 |
107 | for (VolumeAttachment volumeAttachment: volumeAttachmentApi.listAttachmentsOnServer(server.getId())) {
108 | System.out.println(" " + volumeAttachment);
109 | }
110 | }
111 |
112 | /**
113 | * Always close your service when you're done with it.
114 | */
115 | public void close() {
116 | closeQuietly(compute.getContext());
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/UpdateLoadBalancers.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudloadbalancers;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.util.concurrent.TimeoutException;
24 |
25 | import org.jclouds.ContextBuilder;
26 | import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi;
27 | import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
28 | import org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateLoadBalancer;
29 | import org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi;
30 | import org.jclouds.rackspace.cloudloadbalancers.v1.predicates.LoadBalancerPredicates;
31 |
32 | /**
33 | * This example updates a Load Balancer.
34 | *
35 | * @author Everett Toews
36 | */
37 | public class UpdateLoadBalancers {
38 | private CloudLoadBalancersApi clb;
39 | private LoadBalancerApi lbApi;
40 |
41 | /**
42 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
43 | *
44 | * The first argument (args[0]) must be your username
45 | * The second argument (args[1]) must be your API key
46 | */
47 | public static void main(String[] args) {
48 | UpdateLoadBalancers updateLoadBalancers = new UpdateLoadBalancers();
49 |
50 | try {
51 | updateLoadBalancers.init(args);
52 | LoadBalancer loadBalancer = updateLoadBalancers.getLoadBalancer();
53 | updateLoadBalancers.updateLoadBalancer(loadBalancer);
54 | }
55 | catch (Exception e) {
56 | e.printStackTrace();
57 | }
58 | finally {
59 | updateLoadBalancers.close();
60 | }
61 | }
62 |
63 | private void init(String[] args) {
64 | // The provider configures jclouds To use the Rackspace Cloud (US)
65 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudloadbalancers-uk"
66 | String provider = "rackspace-cloudloadbalancers-us";
67 |
68 | String username = args[0];
69 | String apiKey = args[1];
70 |
71 | clb = ContextBuilder.newBuilder(provider)
72 | .credentials(username, apiKey)
73 | .buildApi(CloudLoadBalancersApi.class);
74 | lbApi = clb.getLoadBalancerApiForZone(Constants.ZONE);
75 | }
76 |
77 | private LoadBalancer getLoadBalancer() {
78 | for (LoadBalancer loadBalancer: lbApi.list().concat()) {
79 | if (loadBalancer.getName().startsWith(Constants.NAME)) {
80 | return loadBalancer;
81 | }
82 | }
83 |
84 | throw new RuntimeException(Constants.NAME + " not found. Run a CreateLoadBalancer* example first.");
85 | }
86 |
87 | private void updateLoadBalancer(LoadBalancer loadBalancer) throws TimeoutException {
88 | System.out.println("Update Load Balancer");
89 |
90 | UpdateLoadBalancer updateLB = UpdateLoadBalancer.builder()
91 | .name(Constants.NAME + "-update")
92 | .protocol("HTTPS")
93 | .port(443)
94 | .algorithm(LoadBalancer.Algorithm.RANDOM)
95 | .build();
96 |
97 | lbApi.update(loadBalancer.getId(), updateLB);
98 |
99 | // Wait for the Load Balancer to become Active before moving on
100 | // If you want to know what's happening during the polling, enable logging. See
101 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
102 | if (!LoadBalancerPredicates.awaitAvailable(lbApi).apply(loadBalancer)) {
103 | throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer);
104 | }
105 |
106 | System.out.println(" " + true);
107 | }
108 |
109 | /**
110 | * Always close your service when you're done with it.
111 | */
112 | public void close() {
113 | closeQuietly(clb);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/camel-notifications/src/main/resources/META-INF/spring/camel-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | ${email.to}
46 |
47 |
48 | ${email.from}
49 |
50 |
51 | Running nodes in the cloud
52 |
53 |
54 | ${body.size} != 0
55 |
56 | request.body.collect { it.id }
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | org.jclouds.compute.ComputeServiceContext
102 |
103 |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/Authentication.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.Properties;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.compute.ComputeService;
28 | import org.jclouds.compute.ComputeServiceContext;
29 | import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
30 | import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
31 | import org.jclouds.openstack.nova.v2_0.NovaApi;
32 | import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
33 | import org.jclouds.rest.RestContext;
34 |
35 | /**
36 | * To authenticate using jclouds you need to provide your credentials to a Context as in the init() method below.
37 | * Authentication occurs on your first actual interaction with the Rackspace Cloud (i.e. the very first time
38 | * you call a method that needs to talk to the cloud). Once you are authenticated you receive a token that is
39 | * cached and you won't reauthenticate for subsequent calls. If your token expires before the JVM quits, jclouds
40 | * will automatically handle reauthentication and get a new token for you.
41 | *
42 | * If authentication doesn't work, the call will result in an org.jclouds.rest.AuthorizationException
43 | *
44 | * This example demostrates how you would authenticate via username and password or API key. The default is
45 | * authentication via API key, which is used in the rest of the examples in this package.
46 | *
47 | * @author Everett Toews
48 | */
49 | public class Authentication implements Closeable {
50 | private ComputeService compute;
51 | private RestContext nova;
52 |
53 | /**
54 | * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
55 | *
56 | * The first argument (args[0]) must be your username
57 | * The second argument (args[1]) must be your API key or password
58 | * [Optional] The third argument (args[2]) must be "password" if password authentication is used,
59 | * otherwise default to using API key.
60 | */
61 | public static void main(String[] args) {
62 | Authentication authentication = new Authentication();
63 |
64 | try {
65 | authentication.init(args);
66 | authentication.authenticateOnCall();
67 | }
68 | finally {
69 | authentication.close();
70 | }
71 | }
72 |
73 | private void init(String[] args) {
74 | // The provider configures jclouds To use the Rackspace Cloud (US)
75 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
76 | String provider = "rackspace-cloudservers-us";
77 |
78 | String username = args[0];
79 | String credential = args[1];
80 |
81 | Properties overrides = new Properties();
82 |
83 | if (args.length == 3 && "password".equals(args[2])) {
84 | overrides.put(KeystoneProperties.CREDENTIAL_TYPE, CredentialTypes.PASSWORD_CREDENTIALS);
85 | }
86 |
87 | ComputeServiceContext context = ContextBuilder.newBuilder(provider)
88 | .credentials(username, credential)
89 | .overrides(overrides)
90 | .buildView(ComputeServiceContext.class);
91 | compute = context.getComputeService();
92 | nova = context.unwrap();
93 | }
94 |
95 | /**
96 | * Calling getConfiguredZones() causes jclouds to authenticate. If authentication doesn't work, the call to
97 | * getConfiguredZones() will result in an org.jclouds.rest.AuthorizationException
98 | */
99 | private void authenticateOnCall() {
100 | System.out.println("Authenticate On Call");
101 |
102 | nova.getApi().getConfiguredZones();
103 |
104 | System.out.println(" Authenticated");
105 | }
106 |
107 | /**
108 | * Always close your service when you're done with it.
109 | */
110 | public void close() {
111 | closeQuietly(compute.getContext());
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/CreateSnapshot.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to jclouds, Inc. (jclouds) under one or more
3 | * contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. jclouds licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.jclouds.examples.rackspace.cloudblockstorage;
20 |
21 | import static com.google.common.io.Closeables.closeQuietly;
22 |
23 | import java.io.Closeable;
24 | import java.util.concurrent.TimeoutException;
25 |
26 | import org.jclouds.ContextBuilder;
27 | import org.jclouds.openstack.cinder.v1.CinderApi;
28 | import org.jclouds.openstack.cinder.v1.CinderApiMetadata;
29 | import org.jclouds.openstack.cinder.v1.CinderAsyncApi;
30 | import org.jclouds.openstack.cinder.v1.domain.Snapshot;
31 | import org.jclouds.openstack.cinder.v1.domain.Volume;
32 | import org.jclouds.openstack.cinder.v1.features.SnapshotApi;
33 | import org.jclouds.openstack.cinder.v1.features.VolumeApi;
34 | import org.jclouds.openstack.cinder.v1.options.CreateSnapshotOptions;
35 | import org.jclouds.openstack.cinder.v1.predicates.SnapshotPredicates;
36 | import org.jclouds.rest.RestContext;
37 |
38 | /**
39 | * This example creates a snapshot of a volume.
40 | *
41 | * @author Everett Toews
42 | */
43 | public class CreateSnapshot implements Closeable {
44 | private RestContext cinder;
45 | private VolumeApi volumeApi;
46 | private SnapshotApi snapshotApi;
47 |
48 | /**
49 | * To get a username and API key see
50 | * http://www.jclouds.org/documentation/quickstart/rackspace/
51 | *
52 | * The first argument (args[0]) must be your username The second argument
53 | * (args[1]) must be your API key
54 | */
55 | public static void main(String[] args) {
56 | CreateSnapshot createSnapshot = new CreateSnapshot();
57 |
58 | try {
59 | createSnapshot.init(args);
60 | Volume volume = createSnapshot.getVolume();
61 | createSnapshot.createSnapshot(volume);
62 | }
63 | catch (Exception e) {
64 | e.printStackTrace();
65 | }
66 | finally {
67 | createSnapshot.close();
68 | }
69 | }
70 |
71 | private void init(String[] args) {
72 | // The provider configures jclouds To use the Rackspace Cloud (US)
73 | // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudblockstorage-uk"
74 | String provider = "rackspace-cloudblockstorage-us";
75 |
76 | String username = args[0];
77 | String apiKey = args[1];
78 |
79 | cinder = ContextBuilder.newBuilder(provider)
80 | .credentials(username, apiKey)
81 | .build(CinderApiMetadata.CONTEXT_TOKEN);
82 | volumeApi = cinder.getApi().getVolumeApiForZone(Constants.ZONE);
83 | snapshotApi = cinder.getApi().getSnapshotApiForZone(Constants.ZONE);
84 | }
85 |
86 | /**
87 | * @return Volume The Volume created in the CreateVolumeAndAttach example
88 | */
89 | private Volume getVolume() {
90 | for (Volume volume: volumeApi.list()) {
91 | if (volume.getName().startsWith(Constants.NAME)) {
92 | return volume;
93 | }
94 | }
95 |
96 | throw new RuntimeException(Constants.NAME + " not found. Run the CreateVolumeAndAttach example first.");
97 | }
98 |
99 | private void createSnapshot(Volume volume) throws TimeoutException {
100 | System.out.println("Create Snapshot");
101 |
102 | CreateSnapshotOptions options = CreateSnapshotOptions.Builder
103 | .name(Constants.NAME)
104 | .description("Snapshot of " + volume.getId());
105 |
106 | Snapshot snapshot = snapshotApi.create(volume.getId(), options);
107 |
108 | // Wait for the snapshot to become Available before moving on
109 | // If you want to know what's happening during the polling, enable logging. See
110 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
111 | if (!SnapshotPredicates.awaitAvailable(snapshotApi).apply(snapshot)) {
112 | throw new TimeoutException("Timeout on volume: " + volume);
113 | }
114 |
115 | System.out.println(" " + snapshot);
116 | }
117 |
118 | /**
119 | * Always close your service when you're done with it.
120 | */
121 | public void close() {
122 | closeQuietly(cinder);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------