Repository: jclouds-labs-google
Updated Branches:
  refs/heads/master 867c785be -> 04c02a993


Use InstanceTemplate.name as opposed to ignoring it.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/04c02a99
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/04c02a99
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/04c02a99

Branch: refs/heads/master
Commit: 04c02a993209a6a100104e747837ed2ef63506dc
Parents: 8895953
Author: Adrian Cole <[email protected]>
Authored: Thu Nov 6 21:00:36 2014 -0800
Committer: Adrian Cole <[email protected]>
Committed: Fri Nov 7 07:57:33 2014 -0800

----------------------------------------------------------------------
 .../binders/InstanceBinder.java                 | 57 --------------------
 .../GoogleComputeEngineServiceAdapter.java      |  6 ++-
 .../GoogleComputeEngineHttpApiModule.java       | 30 -----------
 .../domain/templates/InstanceTemplate.java      | 17 ++----
 .../features/InstanceApi.java                   |  5 +-
 .../features/InstanceApiExpectTest.java         | 12 +++--
 .../features/InstanceApiLiveTest.java           |  3 +-
 .../features/TargetPoolApiLiveTest.java         |  7 +--
 8 files changed, 22 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
deleted file mode 100644
index aae9d38..0000000
--- 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * 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.
- */
-package org.jclouds.googlecomputeengine.binders;
-
-import java.net.URI;
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.rest.MapBinder;
-import org.jclouds.rest.binders.BindToJsonPayload;
-
-import com.google.common.base.Function;
-
-public final class InstanceBinder implements MapBinder {
-
-   private final BindToJsonPayload jsonBinder;
-   private final Function<String, URI> machineTypesToURI;
-
-   @Inject InstanceBinder(BindToJsonPayload jsonBinder,
-         @Named("machineTypeToURI") Function<String, URI> machineTypesToURI) {
-      this.jsonBinder = jsonBinder;
-      this.machineTypesToURI = machineTypesToURI;
-   }
-
-   @Override public <R extends HttpRequest> R bindToRequest(R request, 
Map<String, Object> postParams) {
-      InstanceTemplate template = (InstanceTemplate) 
postParams.get("template");
-      template.name(postParams.get("name").toString());
-
-      if (template.machineTypeName() != null) {
-         
template.machineType(machineTypesToURI.apply(template.machineTypeName()));
-         template.machineTypeName(null);
-      }
-      return bindToRequest(request, template);
-   }
-
-   @Override public <R extends HttpRequest> R bindToRequest(R request, Object 
input) {
-      return jsonBinder.bindToRequest(request, input);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
index 586f137..9a9187e 100644
--- 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
+++ 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
@@ -142,7 +142,9 @@ public final class GoogleComputeEngineServiceAdapter
 
       disks.addAll(options.getDisks());
 
-      InstanceTemplate instanceTemplate = new 
InstanceTemplate().machineType(hardware.getUri());
+      InstanceTemplate instanceTemplate = new InstanceTemplate()
+            .name(name)
+            .machineType(hardware.getUri());
 
       if (options.isEnableNat()) {
          instanceTemplate.addNetworkInterface(options.getNetwork().get(), 
Type.ONE_TO_ONE_NAT);
@@ -167,7 +169,7 @@ public final class GoogleComputeEngineServiceAdapter
 
       String zone = template.getLocation().getId();
       InstanceApi instanceApi = api.getInstanceApi(userProject.get(), zone);
-      Operation operation = instanceApi.create(name, instanceTemplate);
+      Operation operation = instanceApi.create(instanceTemplate);
 
       if (options.shouldBlockUntilRunning()) {
          waitOperationDone(operation);

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
index 23fed76..20e26d7 100644
--- 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
+++ 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
@@ -20,7 +20,6 @@ import static com.google.common.base.Suppliers.compose;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
 
-import java.net.URI;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.inject.Named;
@@ -28,10 +27,8 @@ import javax.inject.Singleton;
 
 import org.jclouds.domain.Credentials;
 import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.compute.domain.SlashEncodedIds;
 import 
org.jclouds.googlecomputeengine.handlers.GoogleComputeEngineErrorHandler;
 import org.jclouds.http.HttpErrorHandler;
-import org.jclouds.http.Uris;
 import org.jclouds.http.annotation.ClientError;
 import org.jclouds.http.annotation.Redirection;
 import org.jclouds.http.annotation.ServerError;
@@ -94,31 +91,4 @@ public final class GoogleComputeEngineHttpApiModule extends 
HttpApiModule<Google
                  }
               }, creds), seconds, SECONDS);
    }
-
-   @Provides
-   @Singleton
-   @Named("machineTypeToURI") Function<String, URI> machineTypeNameToURI(
-         @Provider final Supplier<URI> endpoint, @UserProject final 
Supplier<String> userProject) {
-      return new Function<String, URI>() {
-         @Override
-         public URI apply(String input) {
-            SlashEncodedIds zoneAndMachineType = 
SlashEncodedIds.fromSlashEncoded(input);
-            return 
Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
-                    
.appendPath("/zones/").appendPath(zoneAndMachineType.left())
-                    
.appendPath("/machineTypes/").appendPath(zoneAndMachineType.right()).build();
-         }
-      };
-   }
-
-   @Provides
-   @Singleton
-   @Named("networkToURI") Function<String, URI> networkNameToURI(@Provider 
final Supplier<URI> endpoint,
-                                                                 @UserProject 
final Supplier<String> userProject) {
-      return new Function<String, URI>() {
-         @Override public URI apply(String input) {
-            return 
Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
-                    .appendPath("/global/networks/").appendPath(input).build();
-         }
-      };
-   }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
index f726234..c544453 100644
--- 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
+++ 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
@@ -24,6 +24,7 @@ import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
+import org.jclouds.googlecomputeengine.domain.Image;
 import 
org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
 import 
org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
 import org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
@@ -34,6 +35,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 /** Optional information for creating an instance. */
+// TODO! this is dangerously similarly named to the InstanceTemplate resource!
 public class InstanceTemplate {
 
    public static final class PersistentDisk {
@@ -107,7 +109,6 @@ public class InstanceTemplate {
    private List<PersistentDisk> disks = Lists.newArrayList();
    private List<NetworkInterface> networkInterfaces = Lists.newArrayList();
    private Map<String, String> metadata = Maps.newLinkedHashMap();
-   private String machineTypeName;
 
    /**
     * @see org.jclouds.googlecomputeengine.domain.Instance#name()
@@ -134,7 +135,7 @@ public class InstanceTemplate {
    }
 
    /**
-    * @see org.jclouds.googlecomputeengine.domain.Instance#image()
+    * @see Image#selfLink()
     */
    public URI image() {
       return image;
@@ -158,18 +159,6 @@ public class InstanceTemplate {
    }
 
    /**
-    * @see org.jclouds.googlecomputeengine.domain.Instance#machineTypeName()
-    */
-   public String machineTypeName() {
-      return machineTypeName;
-   }
-
-   public InstanceTemplate machineTypeName(String machineTypeName) {
-      this.machineTypeName = machineTypeName;
-      return this;
-   }
-
-   /**
     * @see org.jclouds.googlecomputeengine.domain.Instance#disks()
     */
    public List<PersistentDisk> disks() {

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
index 41524ec..17ec3e8 100644
--- 
a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
+++ 
b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
@@ -38,7 +38,6 @@ import javax.ws.rs.QueryParam;
 import org.jclouds.Fallbacks.NullOnNotFoundOr404;
 import 
org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyIteratorOnNotFoundOr404;
 import 
org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
-import org.jclouds.googlecomputeengine.binders.InstanceBinder;
 import org.jclouds.googlecomputeengine.binders.MetadataBinder;
 import org.jclouds.googlecomputeengine.domain.Instance;
 import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -78,7 +77,6 @@ public interface InstanceApi {
    /**
     * Creates a instance resource in the specified project using the data 
included in the request.
     *
-    * @param instance this name of the instance to be created
     * @param template the instance template
     * @return an Operation resource. To check on the status of an operation, 
poll the Operations resource returned to
     *         you, and look for the status field.
@@ -87,8 +85,7 @@ public interface InstanceApi {
    @POST
    @Produces(APPLICATION_JSON)
    @OAuthScopes(COMPUTE_SCOPE)
-   @MapBinder(InstanceBinder.class)
-   Operation create(@PayloadParam("name") String instance, 
@PayloadParam("template") InstanceTemplate template);
+   Operation create(@BinderParam(BindToJsonPayload.class) InstanceTemplate 
template);
 
    /** Deletes an instance by name and returns the operation in progress, or 
null if not found. */
    @Named("Instances:delete")

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
 
b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
index 03c6876..351cabe 100644
--- 
a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
+++ 
b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
@@ -137,10 +137,12 @@ public class InstanceApiExpectTest extends 
BaseGoogleComputeEngineApiExpectTest
               TOKEN_RESPONSE, insert,
               CREATE_INSTANCE_RESPONSE)).getInstanceApi("myproject", 
"us-central1-a");
 
-      InstanceTemplate options = new 
InstanceTemplate().machineTypeName("us-central1-a/n1-standard-1")
+      InstanceTemplate options = new InstanceTemplate()
+              .name("test-1")
+              .machineType(URI.create(BASE_URL + 
"/myproject/zones/us-central1-a/machineTypes/n1-standard-1"))
               .addNetworkInterface(URI.create(BASE_URL + 
"/myproject/global/networks/default"));
 
-      assertEquals(api.create("test-1", options), new 
ParseZoneOperationTest().expected());
+      assertEquals(api.create(options), new 
ParseZoneOperationTest().expected());
    }
 
    public void testInsertInstanceResponseIs2xxAllOptions() {
@@ -161,7 +163,9 @@ public class InstanceApiExpectTest extends 
BaseGoogleComputeEngineApiExpectTest
               requestForScopes(COMPUTE_SCOPE),
               TOKEN_RESPONSE, insert, 
insertInstanceResponse)).getInstanceApi("myproject", "us-central1-a");
 
-      InstanceTemplate options = new 
InstanceTemplate().machineTypeName("us-central1-a/n1-standard-1")
+      InstanceTemplate options = new InstanceTemplate()
+              .name("test-0")
+              .machineType(URI.create(BASE_URL + 
"/myproject/zones/us-central1-a/machineTypes/n1-standard-1"))
               .addNetworkInterface(
                     URI.create(BASE_URL + 
"/myproject/global/networks/default"),
                     Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
@@ -172,7 +176,7 @@ public class InstanceApiExpectTest extends 
BaseGoogleComputeEngineApiExpectTest
               .addServiceAccount(Instance.ServiceAccount.create("default", 
ImmutableList.of("myscope")))
               .addMetadata("aKey", "aValue");
 
-      assertEquals(api.create("test-0", options), new 
ParseZoneOperationTest().expected());
+      assertEquals(api.create(options), new 
ParseZoneOperationTest().expected());
    }
 
    public void testDeleteInstanceResponseIs2xx() {

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
 
b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
index a7ec619..161844b 100644
--- 
a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
+++ 
b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
@@ -82,6 +82,7 @@ public class InstanceApiLiveTest extends 
BaseGoogleComputeEngineApiLiveTest {
                         .get()
                         .selfLink();
       instance = new InstanceTemplate()
+              .name(INSTANCE_NAME)
               .machineType(getDefaultMachineTypeUrl(userProject.get()))
               .addNetworkInterface(getNetworkUrl(userProject.get(), 
INSTANCE_NETWORK_NAME),
                                    
Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
@@ -113,7 +114,7 @@ public class InstanceApiLiveTest extends 
BaseGoogleComputeEngineApiLiveTest {
       DiskCreationOptions diskCreationOptions = new 
DiskCreationOptions().sourceImage(instance.image());
       assertOperationDoneSuccessfully(diskApi().create(BOOT_DISK_NAME, 
DEFAULT_DISK_SIZE_GB, diskCreationOptions));
       
assertOperationDoneSuccessfully(diskApi().create("instance-live-test-disk", 
DEFAULT_DISK_SIZE_GB));
-      assertOperationDoneSuccessfully(api().create(INSTANCE_NAME, instance));
+      assertOperationDoneSuccessfully(api().create(instance));
    }
 
    @Test(groups = "live", dependsOnMethods = "testInsertInstance")

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/04c02a99/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
 
b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
index 37fcacf..038f04f 100644
--- 
a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
+++ 
b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
@@ -16,6 +16,7 @@
  */
 package org.jclouds.googlecomputeengine.features;
 
+import static 
org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT;
 import static 
org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotEquals;
@@ -85,9 +86,9 @@ public class TargetPoolApiLiveTest extends 
BaseGoogleComputeEngineApiLiveTest {
 
       // Make and instanceTemplate
       InstanceTemplate instanceTemplate = new InstanceTemplate()
+            .name(INSTANCE_NAME)
             .machineType(getDefaultMachineTypeUrl(userProject.get()))
-            .addNetworkInterface(getNetworkUrl(userProject.get(), 
INSTANCE_NETWORK_NAME),
-                                 
Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
+            .addNetworkInterface(getNetworkUrl(userProject.get(), 
INSTANCE_NETWORK_NAME), ONE_TO_ONE_NAT)
             .addMetadata("mykey", "myvalue")
             .description("a description")
             .addDisk(Instance.AttachedDisk.Mode.READ_WRITE, 
getDiskUrl(userProject.get(), BOOT_DISK_NAME),
@@ -105,7 +106,7 @@ public class TargetPoolApiLiveTest extends 
BaseGoogleComputeEngineApiLiveTest {
                   .create(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, 
diskCreationOptions));
 
       // Create an instance.
-      assertOperationDoneSuccessfully(instanceApi.create(INSTANCE_NAME, 
instanceTemplate));
+      assertOperationDoneSuccessfully(instanceApi.create(instanceTemplate));
       Instance instance = instanceApi.get(INSTANCE_NAME);
       instances = new ArrayList<URI>();
       instances.add(instance.selfLink());

Reply via email to