You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jclouds.apache.org by mikolajz <no...@github.com> on 2014/04/17 18:39:43 UTC

[jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Rackspace example)
You can merge this Pull Request by running:

  git pull https://github.com/mikolajz/jclouds-examples master

Or you can view, comment on it, or merge it online at:

  https://github.com/jclouds/jclouds-examples/pull/44

-- Commit Summary --

  * Add an example of using jclouds to create a GCE instance (based on a Rackspace example)

-- File Changes --

    A google/pom.xml (51)
    A google/src/main/java/org/jclouds/examples/google/computeengine/Constants.java (34)
    A google/src/main/java/org/jclouds/examples/google/computeengine/CreateServer.java (182)
    A google/src/main/java/org/jclouds/examples/google/computeengine/Utils.java (31)

-- Patch Links --

https://github.com/jclouds/jclouds-examples/pull/44.patch
https://github.com/jclouds/jclouds-examples/pull/44.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +      }
> +      return result;
> +   }
> +
> +   /**
> +    * This method uses the generic ComputeService.listImages() to find the image.
> +    * 
> +    * @return A Debian Wheezy Image 
> +    */
> +   private Image getImage() {
> +      System.out.format("  Images%n");
> +
> +      Set<? extends Image> images = computeService.listImages();
> +      Image result = null;
> +
> +      for (Image image: images) {

`image : images`?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032770

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
> +/**
> + * This example creates an Debian Wheezy server on a f1-micro instance on the
> + * Google Compute Engine.
> + *
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public class CreateServer implements Closeable {
> +   private final ComputeService computeService;
> +
> +   /**
> +    * To get a service account and its private see [TODO: write some
> +    * documentation on the website and put a link to it]
> +    * 
> +    * The first argument (args[0]) must be your service account name
> +    * The second argument (args[1]) must a path to your service account
> +    *     private key PEM file (without a password).

Ah right, I misunderstood. I thought these were the credentials to access the deployed server, not the credentials used to authenticate with the provider. Javadoc is fine then. That might be related to:
https://issues.apache.org/jira/plugins/servlet/mobile#issue/JCLOUDS-433

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11788522

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   private Image getImage() {
> +      System.out.format("  Images%n");
> +
> +      Set<? extends Image> images = computeService.listImages();
> +      Image result = null;
> +
> +      for (Image image: images) {
> +         System.out.format("    %s%n", image);
> +         if (image.getOperatingSystem().getVersion().equals("debian.7.wheezy")) {
> +            result = image;
> +         }
> +      }
> +
> +      if (result == null) {
> +         System.err.println("Image with Debian Wheezy operating system not found. Using first image found.%n");
> +         result = images.iterator().next();

See previous comment

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032767

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.jclouds.examples.google.computeengine;
> +
> +import static java.util.concurrent.TimeUnit.SECONDS;
> +
> +/**
> + * Constants used by the Google Compute Engine Examples.
> + * 
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public interface Constants {
> +   public static final String PROVIDER = System.getProperty("provider.cs", "google-compute-engine");

Fine with keeping things consistent with the Rackspace examples wherever they were the inspiration. Your call ;-)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12258660

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +    Unless required by applicable law or agreed to in writing, software
> +    distributed under the License is distributed on an "AS IS" BASIS,
> +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +    See the License for the specific language governing permissions and
> +    limitations under the License.
> +
> +-->
> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> +  <modelVersion>4.0.0</modelVersion>
> +  <properties>
> +    <jclouds.version>1.7.1</jclouds.version>
> +  </properties>
> +  <groupId>org.apache.jclouds.examples</groupId>
> +  <artifactId>google-examples</artifactId>
> +  <version>1.0</version>

Current version for the others (e.g. Rackspace) appears to be 1.7.3-SNAPSHOT?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032724

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;
> +
> +import java.io.FileInputStream;
> +import java.io.IOException;
> +
> +/**
> + * Utility functions that can be shared by multiple examples.
> + *
> + * @author Mikolaj Zalewski
> + */
> +public class Utils {
> +   public static String readKeyFile(String path) throws IOException {
> +   	// Note: when using Java 7 you can use Files.readAllBytes for a shorter code.

Can `Files.toString` be used instead also in Java 6?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11753739

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;
> +
> +import java.io.FileInputStream;
> +import java.io.IOException;
> +
> +/**
> + * Utility functions that can be shared by multiple examples.
> + *
> + * @author Mikolaj Zalewski
> + */
> +public class Utils {
> +   public static String readKeyFile(String path) throws IOException {
> +   	// Note: when using Java 7 you can use Files.readAllBytes for a shorter code.

According to documentation (http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html), the whole java.nio.file.Files class is since Java 1.7. But maybe we don't care about Java 6?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11787029

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
Good to have GCE examples, thanks @mikolajz!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44?utm_campaign=website&utm_source=sendgrid.com&utm_medium=email#issuecomment-40762260

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
[Merged](https://git-wip-us.apache.org/repos/asf?p=jclouds-examples.git;a=commit;h=82f3903e089ca081c74e4288da4d4a7f38ba9abf). Thanks @mikolajz!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44#issuecomment-41508715

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> +/**
> + * This example creates an Debian Wheezy server on a f1-micro instance on the
> + * Google Compute Engine.
> + *
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public class CreateServer implements Closeable {
> +   private final ComputeService computeService;
> +
> +   /**
> +    * To get a service account and its private see [TODO: write some
> +    * documentation on the website and put a link to it]
> +    * 
> +    * The first argument (args[0]) must be your service account name
> +    * The second argument (args[1]) must a path to your service account
> +    *     private key PEM file (without a password).

I don't understand the whole data flow, so maybe I miss some code path somewhere, but it seems that the credentials I pass in ComputeServiceContext gets to OAuthCredentialsSupplier (it's bound to Supplier<OAuthCredentials>). The latter calls OAuthCredentialsForCredentials.load() -> org.jclouds.crypto.Pems.privateKeySpec() and that function doesn't seem to even support "-----BEGIN ENCRYPTED PRIVATE KEY-----"

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11786996

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> + */
> +package org.jclouds.examples.google.computeengine;
> +
> +import static java.util.concurrent.TimeUnit.SECONDS;
> +
> +/**
> + * Constants used by the Google Compute Engine Examples.
> + * 
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public interface Constants {
> +   public static final String PROVIDER = System.getProperty("provider.cs", "google-compute-engine");
> +   public static final String ZONE = System.getProperty("zone", "europe-west1-a");
> +
> +   public static final String NAME = "jclouds-example";
> +   public static final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20));

How about just `TWENTY_SECONDS`? The fact that it's used as a polling period is not related to the constant? And why is this a string, out of curiosity?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032738

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.jclouds.examples.google.computeengine;
> +
> +import static java.util.concurrent.TimeUnit.SECONDS;
> +
> +/**
> + * Constants used by the Google Compute Engine Examples.
> + * 
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public interface Constants {
> +   public static final String PROVIDER = System.getProperty("provider.cs", "google-compute-engine");

  For this and most other comments, I'm a bit torn, as on one hand they are
in a good direction, on the other I wanted the examples to be similar to
the Rackspace ones, so that users can compare how little change is needed.
But if you think code elegance is more important, I can make the changes.


On Mon, Apr 28, 2014 at 3:09 AM, Andrew Phillips
<no...@github.com>wrote:

> In
> google/src/main/java/org/jclouds/examples/google/computeengine/Constants.java:
>
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.jclouds.examples.google.computeengine;
> > +
> > +import static java.util.concurrent.TimeUnit.SECONDS;
> > +
> > +/**
> > + * Constants used by the Google Compute Engine Examples.
> > + *
> > + * @author Mikolaj Zalewski (based on code by Everett Toews)
> > + */
> > +public interface Constants {
> > +   public static final String PROVIDER = System.getProperty("provider.cs", "google-compute-engine");
>
> Actually, I don't think public static final are needed here - values in
> interfaces are public, static and final automatically?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/jclouds/jclouds-examples/pull/44/files#r12032732>
> .
>

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12257667

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   private Hardware getHardware() {
> +      System.out.format("  Hardware Profiles%n");
> +
> +      Set<? extends Hardware> profiles = computeService.listHardwareProfiles();
> +      Hardware result = null;
> +
> +      for (Hardware profile: profiles) {
> +         System.out.format("    %s%n", profile);
> +         if (profile.getId().equals(ZONE + "/f1-micro")) {
> +            result = profile;
> +         }
> +      }
> +
> +      if (result == null) {
> +         System.err.println("f1-micro flavor not found. Using first flavor found.%n");
> +         result = profiles.iterator().next();

Are we sure we want to do this? Why not simply fail instead?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032766

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +    the License.  You may obtain a copy of the License at
> +
> +        http://www.apache.org/licenses/LICENSE-2.0
> +
> +    Unless required by applicable law or agreed to in writing, software
> +    distributed under the License is distributed on an "AS IS" BASIS,
> +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +    See the License for the specific language governing permissions and
> +    limitations under the License.
> +
> +-->
> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> +  <modelVersion>4.0.0</modelVersion>
> +  <properties>
> +    <jclouds.version>1.7.1</jclouds.version>

Current version here is 1.7.2. Update?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032725

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> +   private Image getImage() {
> +      System.out.format("  Images%n");
> +
> +      Set<? extends Image> images = computeService.listImages();
> +      Image result = null;
> +
> +      for (Image image: images) {
> +         System.out.format("    %s%n", image);
> +         if (image.getOperatingSystem().getVersion().equals("debian.7.wheezy")) {
> +            result = image;
> +         }
> +      }
> +
> +      if (result == null) {
> +         System.err.println("Image with Debian Wheezy operating system not found. Using first image found.%n");
> +         result = images.iterator().next();

  Same answer - most likely one day Debian Wheezy won't be supported
anymore...


On Mon, Apr 28, 2014 at 3:13 AM, Andrew Phillips
<no...@github.com>wrote:

> In
> google/src/main/java/org/jclouds/examples/google/computeengine/CreateServer.java:
>
> > +   private Image getImage() {
> > +      System.out.format("  Images%n");
> > +
> > +      Set<? extends Image> images = computeService.listImages();
> > +      Image result = null;
> > +
> > +      for (Image image: images) {
> > +         System.out.format("    %s%n", image);
> > +         if (image.getOperatingSystem().getVersion().equals("debian.7.wheezy")) {
> > +            result = image;
> > +         }
> > +      }
> > +
> > +      if (result == null) {
> > +         System.err.println("Image with Debian Wheezy operating system not found. Using first image found.%n");
> > +         result = images.iterator().next();
>
> See previous comment
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/jclouds/jclouds-examples/pull/44/files#r12032767>
> .
>

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12257689

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;

Good catch...thanks, @nacx!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11754332

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;
> +
> +import java.io.FileInputStream;
> +import java.io.IOException;
> +
> +/**
> + * Utility functions that can be shared by multiple examples.
> + *
> + * @author Mikolaj Zalewski
> + */
> +public class Utils {
> +   public static String readKeyFile(String path) throws IOException {
> +   	// Note: when using Java 7 you can use Files.readAllBytes for a shorter code.

Yes, we care. I was referring to the Guava's Files class (as it is a transitive dependency added by jclouds and already present in the classpath).

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11788612

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +    the License.  You may obtain a copy of the License at
> +
> +        http://www.apache.org/licenses/LICENSE-2.0
> +
> +    Unless required by applicable law or agreed to in writing, software
> +    distributed under the License is distributed on an "AS IS" BASIS,
> +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +    See the License for the specific language governing permissions and
> +    limitations under the License.
> +
> +-->
> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> +  <modelVersion>4.0.0</modelVersion>
> +  <properties>
> +    <jclouds.version>1.7.1</jclouds.version>

Thanks!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12258659

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   private Hardware getHardware() {
> +      System.out.format("  Hardware Profiles%n");
> +
> +      Set<? extends Hardware> profiles = computeService.listHardwareProfiles();
> +      Hardware result = null;
> +
> +      for (Hardware profile: profiles) {
> +         System.out.format("    %s%n", profile);
> +         if (profile.getId().equals(ZONE + "/f1-micro")) {
> +            result = profile;
> +         }
> +      }
> +
> +      if (result == null) {
> +         System.err.println("f1-micro flavor not found. Using first flavor found.%n");
> +         result = profiles.iterator().next();

OK. In that case print details of the image we *are* using in the message?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12258662

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +            .credentials(serviceAccountEmailAddress, serviceAccountKey)
> +            .overrides(overrides)
> +            .buildView(ComputeServiceContext.class);
> +      computeService = context.getComputeService();
> +   }
> +
> +   /**
> +    * Create a server based on a Template. This method uses Template.hardwareId() and Template.imageId() to
> +    * also demonstrate iterating through Hardware and Images. Alternatively you do the same without iterating
> +    * using the following Template.
> +    * 
> +    * Template template = computeService.templateBuilder()
> +    *     .locationId(getLocationId())
> +    *     .osFamily(OsFamily.CENTOS)
> +    *     .osVersionMatches("6")
> +    *     .minRam(28*1024)

[minor] Spaces, i.e. `28 * 1024`?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032748

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;

Done.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11787300

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> +            .credentials(serviceAccountEmailAddress, serviceAccountKey)
> +            .overrides(overrides)
> +            .buildView(ComputeServiceContext.class);
> +      computeService = context.getComputeService();
> +   }
> +
> +   /**
> +    * Create a server based on a Template. This method uses Template.hardwareId() and Template.imageId() to
> +    * also demonstrate iterating through Hardware and Images. Alternatively you do the same without iterating
> +    * using the following Template.
> +    * 
> +    * Template template = computeService.templateBuilder()
> +    *     .locationId(getLocationId())
> +    *     .osFamily(OsFamily.CENTOS)
> +    *     .osVersionMatches("6")
> +    *     .minRam(28*1024)

I will fix this (and the colons in for-each loops) in a next patch.


On Mon, Apr 28, 2014 at 3:10 AM, Andrew Phillips
<no...@github.com>wrote:

> In
> google/src/main/java/org/jclouds/examples/google/computeengine/CreateServer.java:
>
> > +            .credentials(serviceAccountEmailAddress, serviceAccountKey)
> > +            .overrides(overrides)
> > +            .buildView(ComputeServiceContext.class);
> > +      computeService = context.getComputeService();
> > +   }
> > +
> > +   /**
> > +    * Create a server based on a Template. This method uses Template.hardwareId() and Template.imageId() to
> > +    * also demonstrate iterating through Hardware and Images. Alternatively you do the same without iterating
> > +    * using the following Template.
> > +    *
> > +    * Template template = computeService.templateBuilder()
> > +    *     .locationId(getLocationId())
> > +    *     .osFamily(OsFamily.CENTOS)
> > +    *     .osVersionMatches("6")
> > +    *     .minRam(28*1024)
>
> [minor] Spaces, i.e. 28 * 1024?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/jclouds/jclouds-examples/pull/44/files#r12032748>
> .
>

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12257701

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
> +/**
> + * This example creates an Debian Wheezy server on a f1-micro instance on the
> + * Google Compute Engine.
> + *
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public class CreateServer implements Closeable {
> +   private final ComputeService computeService;
> +
> +   /**
> +    * To get a service account and its private see [TODO: write some
> +    * documentation on the website and put a link to it]
> +    * 
> +    * The first argument (args[0]) must be your service account name
> +    * The second argument (args[1]) must a path to your service account
> +    *     private key PEM file (without a password).

Just curiosity, is the passwordless PEM a restriction on the provider, or did you have issues on the jclouds side?

Since jclouds 1.7.2, we support ssh-agent based authentication, so jclouds should be able to use password-protected keys if they have been added to the ssh-agent previously.

Could you give it a try, and change the javadoc accordingly if needed?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11753422

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> +   private Hardware getHardware() {
> +      System.out.format("  Hardware Profiles%n");
> +
> +      Set<? extends Hardware> profiles = computeService.listHardwareProfiles();
> +      Hardware result = null;
> +
> +      for (Hardware profile: profiles) {
> +         System.out.format("    %s%n", profile);
> +         if (profile.getId().equals(ZONE + "/f1-micro")) {
> +            result = profile;
> +         }
> +      }
> +
> +      if (result == null) {
> +         System.err.println("f1-micro flavor not found. Using first flavor found.%n");
> +         result = profiles.iterator().next();

  To be honest, the first reason was that the Rackspace example does it.
However, it also has the advantage that even when GCE will stop providing
f1-micro instances one day, the example will still work.


On Mon, Apr 28, 2014 at 3:12 AM, Andrew Phillips
<no...@github.com>wrote:

> In
> google/src/main/java/org/jclouds/examples/google/computeengine/CreateServer.java:
>
> > +   private Hardware getHardware() {
> > +      System.out.format("  Hardware Profiles%n");
> > +
> > +      Set<? extends Hardware> profiles = computeService.
> listHardwareProfiles();
> > +      Hardware result = null;
> > +
> > +      for (Hardware profile: profiles) {
> > +         System.out.format("    %s%n", profile);
> > +         if (profile.getId().equals(ZONE + "/f1-micro")) {
> > +            result = profile;
> > +         }
> > +      }
> > +
> > +      if (result == null) {
> > +         System.err.println("f1-micro flavor not found. Using first flavor found.%n");
> > +         result = profiles.iterator().next();
>
> Are we sure we want to do this? Why not simply fail instead?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/jclouds/jclouds-examples/pull/44/files#r12032766>
> .
>

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12257684

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;

Add the license header

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11753794

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Ignasi Barrera <no...@github.com>.
Closed #44.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> @@ -0,0 +1,31 @@
> +package org.jclouds.examples.google.computeengine;
> +
> +import java.io.FileInputStream;
> +import java.io.IOException;
> +
> +/**
> + * Utility functions that can be shared by multiple examples.
> + *
> + * @author Mikolaj Zalewski
> + */
> +public class Utils {
> +   public static String readKeyFile(String path) throws IOException {
> +   	// Note: when using Java 7 you can use Files.readAllBytes for a shorter code.

Ah, OK. Done. Also removed the Utils class - I don't need it anymore.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r11789312

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> +    the License.  You may obtain a copy of the License at
> +
> +        http://www.apache.org/licenses/LICENSE-2.0
> +
> +    Unless required by applicable law or agreed to in writing, software
> +    distributed under the License is distributed on an "AS IS" BASIS,
> +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +    See the License for the specific language governing permissions and
> +    limitations under the License.
> +
> +-->
> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> +  <modelVersion>4.0.0</modelVersion>
> +  <properties>
> +    <jclouds.version>1.7.1</jclouds.version>

  Same answer:  I didn't have commit
https://github.com/jclouds/jclouds-examples/commit/300d46022632ddcb4c6682f523760e53319314d1#diff-d1ac1f4fba681d3c7e1065803ca4b89fin
my tree when I've used that pom.xml as the starting point. I will send
a
patch to fix it.


On Mon, Apr 28, 2014 at 3:08 AM, Andrew Phillips
<no...@github.com>wrote:

> In google/pom.xml:
>
> > +    the License.  You may obtain a copy of the License at
> > +
> > +        http://www.apache.org/licenses/LICENSE-2.0
>
> > +
> > +    Unless required by applicable law or agreed to in writing, software
> > +    distributed under the License is distributed on an "AS IS" BASIS,
> > +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> > +    See the License for the specific language governing permissions and
> > +    limitations under the License.
> > +
> > +-->
> > +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> > +  <modelVersion>4.0.0</modelVersion>
> > +  <properties>
> > +    <jclouds.version>1.7.1</jclouds.version>
>
> Current version here is 1.7.2. Update?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/jclouds/jclouds-examples/pull/44/files#r12032725>
> .
>

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12257581

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +      System.out.format("  %s%n", nodeMetadata);
> +      System.out.format("  Instance %s started with IP %s%n", nodeMetadata.getName(), publicAddress);
> +   }
> +
> +   /**
> +    * This method uses the generic ComputeService.listHardwareProfiles() to find the hardware profile.
> +    * 
> +    * @return The Hardware for a f1-micro instance.
> +    */
> +   private Hardware getHardware() {
> +      System.out.format("  Hardware Profiles%n");
> +
> +      Set<? extends Hardware> profiles = computeService.listHardwareProfiles();
> +      Hardware result = null;
> +
> +      for (Hardware profile: profiles) {

Space? `profile : profiles`

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032761

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.jclouds.examples.google.computeengine;
> +
> +import static java.util.concurrent.TimeUnit.SECONDS;
> +
> +/**
> + * Constants used by the Google Compute Engine Examples.
> + * 
> + * @author Mikolaj Zalewski (based on code by Everett Toews)
> + */
> +public interface Constants {
> +   public static final String PROVIDER = System.getProperty("provider.cs", "google-compute-engine");

Actually, I don't think `public static final` are needed here - values in interfaces are public, static and final automatically?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032732

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +      // TODO: make fromHardware(...) and fromImage(...) work as well. Currently,
> +      // fromHardware chooses a deprecated platform and the call fails, while using
> +      // hardwareId() and fromImage() causes no image to be found.
> +      Template template = computeService.templateBuilder()
> +            .locationId(ZONE)
> +            .hardwareId(getHardware().getId())
> +            .imageId(getImage().getId())
> +            .build();
> +      
> +      // This method will continue to poll for the server status and won't
> +      // return until this server is ACTIVE.
> +      // TODO: does GCE also log what's happening during the polling, like for
> +      // Rackspace? If so, add an example for that.
> +      Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup(NAME, 1, template);
> +
> +      NodeMetadata nodeMetadata = nodes.iterator().next();

If we're assuming use of Guava, use `Iterables.getNext`? Or are we trying to stick with "vanilla Java" here?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12032758

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by Andrew Phillips <no...@github.com>.
> +   private Image getImage() {
> +      System.out.format("  Images%n");
> +
> +      Set<? extends Image> images = computeService.listImages();
> +      Image result = null;
> +
> +      for (Image image: images) {
> +         System.out.format("    %s%n", image);
> +         if (image.getOperatingSystem().getVersion().equals("debian.7.wheezy")) {
> +            result = image;
> +         }
> +      }
> +
> +      if (result == null) {
> +         System.err.println("Image with Debian Wheezy operating system not found. Using first image found.%n");
> +         result = images.iterator().next();

See above response.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12258663

Re: [jclouds-examples] Add an example of using jclouds to create a GCE instance (based on a (#44)

Posted by mikolajz <no...@github.com>.
> +    Unless required by applicable law or agreed to in writing, software
> +    distributed under the License is distributed on an "AS IS" BASIS,
> +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +    See the License for the specific language governing permissions and
> +    limitations under the License.
> +
> +-->
> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> +  <modelVersion>4.0.0</modelVersion>
> +  <properties>
> +    <jclouds.version>1.7.1</jclouds.version>
> +  </properties>
> +  <groupId>org.apache.jclouds.examples</groupId>
> +  <artifactId>google-examples</artifactId>
> +  <version>1.0</version>

Sorry for the late response. I didn't have commit
https://github.com/jclouds/jclouds-examples/commit/300d46022632ddcb4c6682f523760e53319314d1#diff-d1ac1f4fba681d3c7e1065803ca4b89fin
my tree when I've used that pom.xml as the starting point. I will send
a
patch to fix it.


On Mon, Apr 28, 2014 at 3:08 AM, Andrew Phillips
<no...@github.com>wrote:

> In google/pom.xml:
>
> > +    Unless required by applicable law or agreed to in writing, software
> > +    distributed under the License is distributed on an "AS IS" BASIS,
> > +    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> > +    See the License for the specific language governing permissions and
> > +    limitations under the License.
> > +
> > +-->
> > +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> > +  <modelVersion>4.0.0</modelVersion>
> > +  <properties>
> > +    <jclouds.version>1.7.1</jclouds.version>
> > +  </properties>
> > +  <groupId>org.apache.jclouds.examples</groupId>
> > +  <artifactId>google-examples</artifactId>
> > +  <version>1.0</version>
>
> Current version for the others (e.g. Rackspace) appears to be
> 1.7.3-SNAPSHOT?
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/jclouds/jclouds-examples/pull/44/files#r12032724>
> .
>

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-examples/pull/44/files#r12257579