You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ab...@apache.org on 2013/09/06 19:39:55 UTC
[06/11] JCLOUDS-209. Move to GCE v1beta15 API,
with new features/methods included
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java
new file mode 100644
index 0000000..e4a1232
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/RouteBinder.java
@@ -0,0 +1,59 @@
+/*
+ * 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.handlers;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.jclouds.googlecomputeengine.options.RouteOptions;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.rest.binders.BindToJsonPayload;
+
+/**
+ * @author Andrew Bayer
+ */
+public class RouteBinder implements MapBinder {
+
+ @Inject
+ private BindToJsonPayload jsonBinder;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ RouteOptions options = (RouteOptions) checkNotNull(postParams.get("options"), "routeOptions");
+ String name = (String) checkNotNull(postParams.get("name"), "name");
+ URI network = (URI) checkNotNull(postParams.get("network"), "network");
+ options.name(name);
+ options.network(network);
+ return bindToRequest(request, options);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ return jsonBinder.bindToRequest(request, input);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java
new file mode 100644
index 0000000..b1070d4
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java
@@ -0,0 +1,129 @@
+/*
+ * 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.options;
+
+import java.net.URI;
+
+/**
+ * Options for attaching disks to instances.
+ *
+ * @author Andrew Bayer
+ * @see <a href="https://developers.google.com/compute/docs/reference/latest/instances/attachDisk"/>
+ */
+public class AttachDiskOptions {
+
+ public enum DiskType {
+ SCRATCH,
+ PERSISTENT
+ }
+
+ public enum DiskMode {
+ READ_WRITE,
+ READ_ONLY
+ }
+
+ private DiskType type;
+ private DiskMode mode;
+ private URI source;
+ private String deviceName;
+ private boolean boot;
+
+ /**
+ * The disk type
+ *
+ * @return the disk type.
+ */
+ public DiskType getType() {
+ return type;
+ }
+
+ /**
+ * The disk mode
+ *
+ * @return the disk mode
+ */
+ public DiskMode getMode() {
+ return mode;
+ }
+
+ /**
+ * The URI of the source disk - optional, if DiskType.SCRATCH is used.
+ *
+ * @return the URI
+ */
+ public URI getSource() {
+ return source;
+ }
+
+ /**
+ * The device name on the instance - optional.
+ *
+ * @return the device name
+ */
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ /**
+ * Indicates that this is a boot disk. VM will use the first partition of the disk for its root filesystem.
+ *
+ * @return true if this is a boot disk, false otherwise
+ */
+ public boolean getBoot() {
+ return boot;
+ }
+
+ /**
+ * @see AttachDiskOptions#getType()
+ */
+ public AttachDiskOptions type(DiskType type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * @see AttachDiskOptions#getMode()
+ */
+ public AttachDiskOptions mode(DiskMode mode) {
+ this.mode = mode;
+ return this;
+ }
+
+ /**
+ * @see AttachDiskOptions#getSource()
+ */
+ public AttachDiskOptions source(URI source) {
+ this.source = source;
+ return this;
+ }
+
+ /**
+ * @see AttachDiskOptions#getDeviceName()
+ */
+ public AttachDiskOptions deviceName(String deviceName) {
+ this.deviceName = deviceName;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.options.AttachDiskOptions#getBoot()
+ */
+ public AttachDiskOptions boot(boolean boot) {
+ this.boot = boot;
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java
new file mode 100644
index 0000000..aeaef6c
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java
@@ -0,0 +1,127 @@
+/*
+ * 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.options;
+
+import java.net.URI;
+import java.util.Date;
+
+/**
+ * Options to set the deprecation status of a resource. Currently only for images.
+ *
+ * @author Andrew Bayer
+ * @see <a href="https://developers.google.com/compute/docs/reference/latest/images/deprecate" />
+ */
+public class DeprecateOptions {
+
+ public enum State {
+ DEPRECATED,
+ OBSOLETE,
+ DELETED
+ }
+
+ private State state;
+ private URI replacement;
+ private Date deprecated;
+ private Date obsolete;
+ private Date deleted;
+
+ /**
+ * The new deprecation state.
+ *
+ * @return the new deprecation state.
+ */
+ public State getState() {
+ return state;
+ }
+
+ /**
+ * Optional URL for replacement of deprecated resource.
+ *
+ * @return the URL
+ */
+ public URI getReplacement() {
+ return replacement;
+ }
+
+ /**
+ * Optional RFC3339 timestamp for when the deprecation state was changed to DEPRECATED.
+ *
+ * @return the timestamp
+ */
+ public Date getDeprecated() {
+ return deprecated;
+ }
+
+ /**
+ * Optional RFC3339 timestamp for when the deprecation state was changed to OBSOLETE.
+ *
+ * @return the timestamp
+ */
+ public Date getObsolete() {
+ return obsolete;
+ }
+
+ /**
+ * Optional RFC3339 timestamp for when the deprecation state was changed to DELETED.
+ *
+ * @return the timestamp
+ */
+ public Date getDeleted() {
+ return deleted;
+ }
+
+ /**
+ * @see DeprecateOptions#getState()
+ */
+ public DeprecateOptions state(State state) {
+ this.state = state;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.options.DeprecateOptions#getReplacement()
+ */
+ public DeprecateOptions replacement(URI replacement) {
+ this.replacement = replacement;
+ return this;
+ }
+
+ /**
+ * @see DeprecateOptions#getDeprecated()
+ */
+ public DeprecateOptions deprecated(Date deprecated) {
+ this.deprecated = deprecated;
+ return this;
+ }
+
+ /**
+ * @see DeprecateOptions#getObsolete()
+ */
+ public DeprecateOptions obsolete(Date obsolete) {
+ this.obsolete = obsolete;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.options.DeprecateOptions#getDeleted()
+ */
+ public DeprecateOptions deleted(Date deleted) {
+ this.deleted = deleted;
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
index cf1c022..5c3437c 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
@@ -16,17 +16,18 @@
*/
package org.jclouds.googlecomputeengine.options;
-import com.google.common.collect.ImmutableSet;
-import org.jclouds.googlecomputeengine.domain.Firewall;
-
import java.net.URI;
import java.util.Set;
+import org.jclouds.googlecomputeengine.domain.Firewall;
+
+import com.google.common.collect.ImmutableSet;
+
/**
* Options to create a firewall.
*
- * @see Firewall
* @author David Alves
+ * @see Firewall
*/
public class FirewallOptions {
@@ -135,6 +136,7 @@ public class FirewallOptions {
*/
public FirewallOptions sourceTags(Set<String> sourceTags) {
this.sourceTags = ImmutableSet.builder();
+ this.sourceTags.addAll(sourceTags);
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java
index 81330ac..2f79f0f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ListOptions.java
@@ -16,15 +16,15 @@
*/
package org.jclouds.googlecomputeengine.options;
-import org.jclouds.http.options.BaseHttpRequestOptions;
-
import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
/**
* Allows to optionally specify a filter, max results and a page token for <code>listFirstPage()</code> REST methods.
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/operations/listFirstPage"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/operations/listFirstPage"/>
*/
public class ListOptions extends BaseHttpRequestOptions {
@@ -65,7 +65,7 @@ public class ListOptions extends BaseHttpRequestOptions {
}
/**
- * Sets Maximum count of results to be returned. Maximum and default value is 100. Acceptable values are 0 to
+ * Sets Maximum count of results to be returned. Maximum and default value is 100. Acceptable items are 0 to
* 100, inclusive. (Default: 100)
*/
public ListOptions maxResults(Integer maxResults) {
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
new file mode 100644
index 0000000..78dde4a
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
@@ -0,0 +1,203 @@
+/*
+ * 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.options;
+
+import java.net.URI;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Options to create a route.
+ *
+ * @author Andrew Bayer
+ * @see org.jclouds.googlecomputeengine.domain.Route
+ */
+public class RouteOptions {
+
+ private String name;
+ private URI network;
+ private String destRange;
+ private URI nextHopInstance;
+ private String nextHopIp;
+ private URI nextHopNetwork;
+ private URI nextHopGateway;
+ private String description;
+ private Integer priority;
+
+ private ImmutableSet.Builder<String> tags = ImmutableSet.builder();
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getName()
+ */
+ public RouteOptions name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getDescription()
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getDescription()
+ */
+ public RouteOptions description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getDestRange()
+ */
+ public String getDestRange() {
+ return destRange;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getDestRange()
+ */
+ public RouteOptions destRange(String destRange) {
+ this.destRange = destRange;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopIp()
+ */
+ public String getNextHopIp() {
+ return nextHopIp;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopIp()
+ */
+ public RouteOptions nextHopIp(String nextHopIp) {
+ this.nextHopIp = nextHopIp;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getPriority()
+ */
+ public Integer getPriority() {
+ return priority;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getPriority()
+ */
+ public RouteOptions priority(Integer priority) {
+ this.priority = priority;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNetwork()
+ */
+ public RouteOptions network(URI network) {
+ this.network = network;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNetwork()
+ */
+ public URI getNetwork() {
+ return network;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopInstance()
+ */
+ public RouteOptions nextHopInstance(URI nextHopInstance) {
+ this.nextHopInstance = nextHopInstance;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopInstance()
+ */
+ public URI getNextHopInstance() {
+ return nextHopInstance;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopNetwork()
+ */
+ public RouteOptions nextHopNetwork(URI nextHopNetwork) {
+ this.nextHopNetwork = nextHopNetwork;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopNetwork()
+ */
+ public URI getNextHopNetwork() {
+ return nextHopNetwork;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopGateway()
+ */
+ public RouteOptions nextHopGateway(URI nextHopGateway) {
+ this.nextHopGateway = nextHopGateway;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getNextHopGateway()
+ */
+ public URI getNextHopGateway() {
+ return nextHopGateway;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getTags()
+ */
+ public Set<String> getTags() {
+ return tags.build();
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getTags()
+ */
+ public RouteOptions addTag(String tag) {
+ this.tags.add(tag);
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Route#getTags()
+ */
+ public RouteOptions tags(Set<String> tags) {
+ this.tags = ImmutableSet.builder();
+ this.tags.addAll(tags);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
new file mode 100644
index 0000000..abd2b4c
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
@@ -0,0 +1,61 @@
+/*
+ * 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.predicates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Operation;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+
+/**
+ * Tests that a Global Operation is done, returning the completed Operation when it is.
+ *
+ * @author David Alves
+ */
+public class GlobalOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
+
+ private final GoogleComputeEngineApi api;
+ private final Supplier<String> project;
+
+ @Inject
+ GlobalOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project) {
+ this.api = api;
+ this.project = project;
+ }
+
+ @Override
+ public boolean apply(AtomicReference<Operation> input) {
+ checkNotNull(input, "input");
+ Operation current = api.getGlobalOperationApiForProject(project.get()).get(input.get().getName());
+ switch (current.getStatus()) {
+ case DONE:
+ input.set(current);
+ return true;
+ case PENDING:
+ case RUNNING:
+ default:
+ return false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/OperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/OperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/OperationDonePredicate.java
deleted file mode 100644
index b58fe61..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/OperationDonePredicate.java
+++ /dev/null
@@ -1,60 +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.predicates;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.inject.Inject;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.config.UserProject;
-import org.jclouds.googlecomputeengine.domain.Operation;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Tests that an Operation is done, returning the completed Operation when it is.
- *
- * @author David Alves
- */
-public class OperationDonePredicate implements Predicate<AtomicReference<Operation>> {
-
- private final GoogleComputeEngineApi api;
- private final Supplier<String> project;
-
- @Inject
- OperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project) {
- this.api = api;
- this.project = project;
- }
-
- @Override
- public boolean apply(AtomicReference<Operation> input) {
- checkNotNull(input, "input");
- Operation current = api.getOperationApiForProject(project.get()).get(input.get().getName());
- switch (current.getStatus()) {
- case DONE:
- input.set(current);
- return true;
- case PENDING:
- case RUNNING:
- default:
- return false;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
new file mode 100644
index 0000000..a4d1b9d
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
@@ -0,0 +1,71 @@
+/*
+ * 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.predicates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.collect.Memoized;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.Region;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+
+/**
+ * Tests that a Global Operation is done, returning the completed Operation when it is.
+ *
+ * @author David Alves
+ */
+public class RegionOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
+
+ private final GoogleComputeEngineApi api;
+ private final Supplier<String> project;
+ private final Supplier<Map<URI, Region>> regions;
+
+ @Inject
+ RegionOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project,
+ @Memoized Supplier<Map<URI, Region>> regions) {
+ this.api = api;
+ this.project = project;
+ this.regions = regions;
+ }
+
+ @Override
+ public boolean apply(AtomicReference<Operation> input) {
+ checkNotNull(input, "input");
+
+ Operation current = api.getRegionOperationApiForProject(project.get())
+ .getInRegion(regions.get().get(input.get().getRegion().get()).getName(),
+ input.get().getName());
+ switch (current.getStatus()) {
+ case DONE:
+ input.set(current);
+ return true;
+ case PENDING:
+ case RUNNING:
+ default:
+ return false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
new file mode 100644
index 0000000..3cca34a
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
@@ -0,0 +1,70 @@
+/*
+ * 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.predicates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.collect.Memoized;
+import org.jclouds.domain.Location;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Operation;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+
+/**
+ * Tests that a Zone Operation is done, returning the completed Operation when it is.
+ *
+ * @author David Alves
+ */
+public class ZoneOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
+
+ private final GoogleComputeEngineApi api;
+ private final Supplier<String> project;
+ private final Supplier<Map<URI, ? extends Location>> zones;
+
+ @Inject
+ ZoneOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project,
+ @Memoized Supplier<Map<URI, ? extends Location>> zones) {
+ this.api = api;
+ this.project = project;
+ this.zones = zones;
+ }
+
+ @Override
+ public boolean apply(AtomicReference<Operation> input) {
+ checkNotNull(input, "input");
+ Operation current = api.getZoneOperationApiForProject(project.get())
+ .getInZone(zones.get().get(input.get().getZone().get()).getId(),
+ input.get().getName());
+ switch (current.getStatus()) {
+ case DONE:
+ input.set(current);
+ return true;
+ case PENDING:
+ case RUNNING:
+ default:
+ return false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
index 38a79e4..44994c0 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
@@ -16,12 +16,13 @@
*/
package org.jclouds.googlecomputeengine;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.reflect.TypeToken;
import org.jclouds.View;
import org.jclouds.apis.internal.BaseApiMetadataTest;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.reflect.TypeToken;
+
/**
* Tests that GoogleComputeApiMetadata is properly registered in ServiceLoader
* <p/>
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java
index a77b058..c9d9c70 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/PageSystemExpectTest.java
@@ -16,6 +16,9 @@
*/
package org.jclouds.googlecomputeengine;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.testng.Assert.assertSame;
+
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.Image;
@@ -26,9 +29,6 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.testng.Assert.assertSame;
-
/**
* A test specifically for the paging system. The code used is common to all list() methods so we're using Images
* but it could be anything else.
@@ -43,7 +43,7 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest {
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/images")
+ ".com/compute/v1beta15/projects/myproject/global/images")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -66,7 +66,7 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest {
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/images?maxResults=3")
+ ".com/compute/v1beta15/projects/myproject/global/images?maxResults=3")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -74,7 +74,7 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest {
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/images?pageToken" +
+ ".com/compute/v1beta15/projects/myproject/global/images?pageToken" +
"=CgVJTUFHRRIbZ29vZ2xlLmNlbnRvcy02LTItdjIwMTIwNjIx&maxResults=3")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -83,7 +83,7 @@ public class PageSystemExpectTest extends BaseGoogleComputeEngineApiExpectTest {
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/images?pageToken" +
+ ".com/compute/v1beta15/projects/myproject/global/images?pageToken" +
"=CgVJTUFHRRIbZ29vZ2xlLmdjZWwtMTAtMDQtdjIwMTIxMTA2&maxResults=3")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
index 91e37ab..925ac6a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
@@ -16,47 +16,62 @@
*/
package org.jclouds.googlecomputeengine.compute;
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.RunNodesException;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.domain.Location;
-import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
-import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.features.InstanceApiExpectTest;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineServiceExpectTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.util.Strings2;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.MediaType;
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.jclouds.googlecomputeengine.features.FirewallApiExpectTest.GET_FIREWALL_REQUEST;
+import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_REQUEST;
+import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_GOOGLE_IMAGES_REQUEST;
+import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_GOOGLE_IMAGES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_PROJECT_IMAGES_REQUEST;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_PROJECT_IMAGES_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.InstanceApiExpectTest.LIST_CENTRAL1B_INSTANCES_REQUEST;
+import static org.jclouds.googlecomputeengine.features.InstanceApiExpectTest.LIST_CENTRAL1B_INSTANCES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.InstanceApiExpectTest.LIST_INSTANCES_REQUEST;
import static org.jclouds.googlecomputeengine.features.InstanceApiExpectTest.LIST_INSTANCES_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.MachineTypeApiExpectTest.LIST_CENTRAL1B_MACHINE_TYPES_REQUEST;
+import static org.jclouds.googlecomputeengine.features.MachineTypeApiExpectTest.LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.MachineTypeApiExpectTest.LIST_MACHINE_TYPES_REQUEST;
import static org.jclouds.googlecomputeengine.features.MachineTypeApiExpectTest.LIST_MACHINE_TYPES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.NetworkApiExpectTest.GET_NETWORK_REQUEST;
-import static org.jclouds.googlecomputeengine.features.OperationApiExpectTest.GET_OPERATION_REQUEST;
-import static org.jclouds.googlecomputeengine.features.OperationApiExpectTest.GET_OPERATION_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_REQUEST;
+import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_RESPONSE;
import static org.jclouds.googlecomputeengine.features.ZoneApiExpectTest.LIST_ZONES_REQ;
import static org.jclouds.googlecomputeengine.features.ZoneApiExpectTest.LIST_ZONES_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.ZoneApiExpectTest.LIST_ZONES_SHORT_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.ZoneOperationApiExpectTest.GET_ZONE_OPERATION_REQUEST;
+import static org.jclouds.googlecomputeengine.features.ZoneOperationApiExpectTest.GET_ZONE_OPERATION_RESPONSE;
import static org.jclouds.util.Strings2.toStringAndClose;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.RunNodesException;
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.domain.Location;
+import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
+import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.googlecomputeengine.features.InstanceApiExpectTest;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineServiceExpectTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.util.Strings2;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
/**
* @author David Alves
@@ -64,20 +79,11 @@ import static org.testng.Assert.assertNotNull;
@Test(groups = "unit")
public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngineServiceExpectTest {
- public static final HttpRequest LIST_GOOGLE_IMAGES_REQUEST = HttpRequest
- .builder()
- .method("GET")
- .endpoint("https://www.googleapis.com/compute/v1beta13/projects/google/images")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public static final HttpResponse LIST_GOOGLE_IMAGES_RESPONSE = HttpResponse.builder().statusCode(200)
- .payload(staticPayloadFromResource("/image_list_single_page.json")).build();
private HttpRequest INSERT_NETWORK_REQUEST = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1beta13/projects/myproject/networks")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/global/networks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromStringWithContentType("{\"name\":\"jclouds-test\",\"IPv4Range\":\"10.0.0.0/8\"}",
@@ -87,12 +93,12 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
private HttpRequest INSERT_FIREWALL_REQUEST = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1beta13/projects/myproject/firewalls")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/global/firewalls")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromStringWithContentType("{\"name\":\"jclouds-test\",\"network\":\"https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/networks/jclouds-test\"," +
- "\"sourceRanges\":[\"10.0.0.0/8\",\"0.0.0.0/0\"],\"allowed\":[{\"IPProtocol\":\"tcp\"," +
+ ".com/compute/v1beta15/projects/myproject/global/networks/jclouds-test\"," +
+ "\"sourceRanges\":[\"10.0.0.0/8\",\"0.0.0.0/0\"],\"sourceTags\":[\"aTag\"],\"allowed\":[{\"IPProtocol\":\"tcp\"," +
"\"ports\":[\"22\"]}," +
"{\"IPProtocol\":\"udp\",\"ports\":[\"22\"]}]}",
MediaType.APPLICATION_JSON))
@@ -104,7 +110,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
" \"id\": \"13024414170909937976\",\n" +
" \"creationTimestamp\": \"2012-10-24T20:13:19.967\",\n" +
" \"selfLink\": \"https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/networks/jclouds-test\",\n" +
+ ".com/compute/v1beta15/projects/myproject/global/networks/jclouds-test\",\n" +
" \"name\": \"jclouds-test\",\n" +
" \"description\": \"test network\",\n" +
" \"IPv4Range\": \"10.0.0.0/8\",\n" +
@@ -114,6 +120,17 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
private HttpResponse SUCESSFULL_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/operation.json")).build();
+ private HttpRequest SET_TAGS_REQUEST = HttpRequest.builder()
+ .method("POST")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/zones/us-central1-a/instances/test-1/setTags")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN)
+ .payload(payloadFromStringWithContentType("{\"items\":[\"aTag\"],\"fingerprint\":\"abcd\"}",
+ MediaType.APPLICATION_JSON))
+ .build();
+
+ private HttpResponse SET_TAGS_RESPONSE = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/operation.json")).build();
private HttpResponse getInstanceResponseForInstanceAndNetworkAndStatus(String instanceName, String networkName,
String status) throws
@@ -149,19 +166,17 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
return HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1beta13/projects/myproject/instances")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/zones/us-central1-a/instances")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromStringWithContentType("{\"name\":\"" + instanceName + "\"," +
"\"machineType\":\"https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/machineTypes/n1-standard-1\"," +
- "\"zone\":\"https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/zones/us-central1-a\"," +
+ ".com/compute/v1beta15/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1\"," +
"\"image\":\"https://www.googleapis" +
- ".com/compute/v1beta13/projects/google/images/gcel-12-04-v20121106\"," +
- "\"tags\":[],\"serviceAccounts\":[]," +
+ ".com/compute/v1beta15/projects/google/global/images/gcel-12-04-v20121106\"," +
+ "\"serviceAccounts\":[]," +
"\"networkInterfaces\":[{\"network\":\"https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/networks/" + networkName + "\"," +
+ ".com/compute/v1beta15/projects/myproject/global/networks/" + networkName + "\"," +
"\"accessConfigs\":[{\"type\":\"ONE_TO_ONE_NAT\"}]}]," +
"\"metadata\":{\"kind\":\"compute#metadata\",\"items\":[{\"key\":\"sshKeys\"," +
"\"value\":\"jclouds:" +
@@ -174,7 +189,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/instances/" + instanceName)
+ ".com/compute/v1beta15/projects/myproject/zones/us-central1-a/instances/" + instanceName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
}
@@ -211,15 +226,29 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
ImmutableMap<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.
<HttpRequest, HttpResponse>builder()
.put(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE)
+ .put(GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE)
.put(LIST_ZONES_REQ, LIST_ZONES_RESPONSE)
.put(LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE)
.put(LIST_GOOGLE_IMAGES_REQUEST, LIST_GOOGLE_IMAGES_RESPONSE)
.put(LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE)
+ .put(LIST_CENTRAL1B_MACHINE_TYPES_REQUEST, LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE)
.build();
ComputeService client = requestsSendResponses(requestResponseMap);
Template template = client.templateBuilder().build();
- Template toMatch = client.templateBuilder().imageId(template.getImage().getId()).build();
+ Hardware defaultSize = client.templateBuilder().build().getHardware();
+
+ Hardware smallest = client.templateBuilder().smallest().build().getHardware();
+ assertEquals(defaultSize, smallest);
+
+ Hardware fastest = client.templateBuilder().fastest().build().getHardware();
+ assertNotNull(fastest);
+
+ assertEquals(client.listHardwareProfiles().size(), 5);
+
+ Template toMatch = client.templateBuilder()
+ .imageId(template.getImage().getId())
+ .build();
assertEquals(toMatch.getImage(), template.getImage());
}
@@ -229,26 +258,27 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
HttpRequest deleteNodeRequest = HttpRequest.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/instances/test-delete-networks")
+ ".com/compute/v1beta15/projects/myproject/zones/us-central1-a/instances/test-delete-networks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpRequest deleteFirewallRequest = HttpRequest.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/firewalls/jclouds-test-delete")
+ ".com/compute/v1beta15/projects/myproject/global/firewalls/jclouds-test-delete")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpRequest deleteNetworkReqquest = HttpRequest.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
- ".com/compute/v1beta13/projects/myproject/networks/jclouds-test-delete")
+ ".com/compute/v1beta15/projects/myproject/global/networks/jclouds-test-delete")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
List<HttpRequest> orderedRequests = ImmutableList.<HttpRequest>builder()
.add(requestForScopes(COMPUTE_READONLY_SCOPE))
+ .add(GET_PROJECT_REQUEST)
.add(getInstanceRequestForInstance("test-delete-networks"))
.add(LIST_PROJECT_IMAGES_REQUEST)
.add(LIST_GOOGLE_IMAGES_REQUEST)
@@ -256,56 +286,41 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
.add(LIST_MACHINE_TYPES_REQUEST)
.add(requestForScopes(COMPUTE_SCOPE))
.add(deleteNodeRequest)
- .add(GET_OPERATION_REQUEST)
+ .add(GET_ZONE_OPERATION_REQUEST)
.add(getInstanceRequestForInstance("test-delete-networks"))
- .add(LIST_PROJECT_IMAGES_REQUEST)
- .add(LIST_GOOGLE_IMAGES_REQUEST)
- .add(LIST_ZONES_REQ)
- .add(LIST_MACHINE_TYPES_REQUEST)
.add(LIST_INSTANCES_REQUEST)
- .add(LIST_PROJECT_IMAGES_REQUEST)
- .add(LIST_GOOGLE_IMAGES_REQUEST)
- .add(LIST_ZONES_REQ)
- .add(LIST_MACHINE_TYPES_REQUEST)
.add(deleteFirewallRequest)
- .add(GET_OPERATION_REQUEST)
+ .add(GET_GLOBAL_OPERATION_REQUEST)
.add(deleteNetworkReqquest)
- .add(GET_OPERATION_REQUEST)
+ .add(GET_GLOBAL_OPERATION_REQUEST)
.build();
List<HttpResponse> orderedResponses = ImmutableList.<HttpResponse>builder()
.add(TOKEN_RESPONSE)
+ .add(GET_PROJECT_RESPONSE)
.add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", Instance
.Status.RUNNING.name()))
.add(LIST_PROJECT_IMAGES_RESPONSE)
.add(LIST_GOOGLE_IMAGES_RESPONSE)
- .add(LIST_ZONES_RESPONSE)
+ .add(LIST_ZONES_SHORT_RESPONSE)
.add(LIST_MACHINE_TYPES_RESPONSE)
.add(TOKEN_RESPONSE)
.add(SUCESSFULL_OPERATION_RESPONSE)
- .add(GET_OPERATION_RESPONSE)
+ .add(GET_ZONE_OPERATION_RESPONSE)
.add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", Instance
.Status.TERMINATED.name()))
- .add(LIST_PROJECT_IMAGES_RESPONSE)
- .add(LIST_GOOGLE_IMAGES_RESPONSE)
- .add(LIST_ZONES_RESPONSE)
- .add(LIST_MACHINE_TYPES_RESPONSE)
.add(getListInstancesResponseForSingleInstanceAndNetworkAndStatus("test-delete-networks",
"test-network", Instance
.Status.TERMINATED.name()))
- .add(LIST_PROJECT_IMAGES_RESPONSE)
- .add(LIST_GOOGLE_IMAGES_RESPONSE)
- .add(LIST_ZONES_RESPONSE)
- .add(LIST_MACHINE_TYPES_RESPONSE)
.add(SUCESSFULL_OPERATION_RESPONSE)
- .add(GET_OPERATION_RESPONSE)
+ .add(GET_GLOBAL_OPERATION_RESPONSE)
.add(SUCESSFULL_OPERATION_RESPONSE)
- .add(GET_OPERATION_RESPONSE)
+ .add(GET_GLOBAL_OPERATION_RESPONSE)
.build();
ComputeService client = orderedRequestsSendResponses(orderedRequests, orderedResponses);
- client.destroyNode("test-delete-networks");
+ client.destroyNode("us-central1-a/test-delete-networks");
}
@@ -314,11 +329,14 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
ImmutableMap<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.
<HttpRequest, HttpResponse>builder()
.put(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE)
+ .put(GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE)
.put(LIST_ZONES_REQ, LIST_ZONES_RESPONSE)
.put(LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE)
+ .put(LIST_CENTRAL1B_INSTANCES_REQUEST, LIST_CENTRAL1B_INSTANCES_RESPONSE)
.put(LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE)
.put(LIST_GOOGLE_IMAGES_REQUEST, LIST_GOOGLE_IMAGES_RESPONSE)
.put(LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE)
+ .put(LIST_CENTRAL1B_MACHINE_TYPES_REQUEST, LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE)
.build();
ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap);
@@ -331,7 +349,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
assertNotNull(apiWhenServersExist.listNodes());
assertEquals(apiWhenServersExist.listNodes().size(), 1);
- assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(), "test-0");
+ assertEquals(apiWhenServersExist.listNodes().iterator().next().getId(), "us-central1-a/test-0");
assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "test-0");
}
@@ -347,65 +365,65 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
List<HttpRequest> orderedRequests = ImmutableList.<HttpRequest>builder()
.add(requestForScopes(COMPUTE_READONLY_SCOPE))
+ .add(GET_PROJECT_REQUEST)
.add(LIST_ZONES_REQ)
.add(LIST_PROJECT_IMAGES_REQUEST)
.add(LIST_GOOGLE_IMAGES_REQUEST)
+ .add(LIST_ZONES_REQ)
.add(LIST_MACHINE_TYPES_REQUEST)
.add(GET_NETWORK_REQUEST)
.add(requestForScopes(COMPUTE_SCOPE))
.add(INSERT_NETWORK_REQUEST)
- .add(GET_OPERATION_REQUEST)
+ .add(GET_GLOBAL_OPERATION_REQUEST)
.add(GET_NETWORK_REQUEST)
.add(GET_FIREWALL_REQUEST)
.add(INSERT_FIREWALL_REQUEST)
- .add(GET_OPERATION_REQUEST)
+ .add(GET_GLOBAL_OPERATION_REQUEST)
.add(LIST_INSTANCES_REQUEST)
.add(LIST_PROJECT_IMAGES_REQUEST)
.add(LIST_GOOGLE_IMAGES_REQUEST)
- .add(LIST_ZONES_REQ)
.add(LIST_MACHINE_TYPES_REQUEST)
.add(createInstanceRequestForInstance("test-1", "jclouds-test", openSshKey))
- .add(GET_OPERATION_REQUEST)
+ .add(GET_ZONE_OPERATION_REQUEST)
+ .add(getInstanceRequestForInstance("test-1"))
+ .add(SET_TAGS_REQUEST)
+ .add(GET_ZONE_OPERATION_REQUEST)
.add(getInstanceRequestForInstance("test-1"))
- .add(LIST_PROJECT_IMAGES_REQUEST)
- .add(LIST_GOOGLE_IMAGES_REQUEST)
- .add(LIST_ZONES_REQ)
- .add(LIST_MACHINE_TYPES_REQUEST)
.build();
List<HttpResponse> orderedResponses = ImmutableList.<HttpResponse>builder()
.add(TOKEN_RESPONSE)
- .add(LIST_ZONES_RESPONSE)
+ .add(GET_PROJECT_RESPONSE)
+ .add(LIST_ZONES_SHORT_RESPONSE)
.add(LIST_PROJECT_IMAGES_RESPONSE)
.add(LIST_GOOGLE_IMAGES_RESPONSE)
+ .add(LIST_ZONES_SHORT_RESPONSE)
.add(LIST_MACHINE_TYPES_RESPONSE)
.add(HttpResponse.builder().statusCode(404).build())
.add(TOKEN_RESPONSE)
.add(SUCESSFULL_OPERATION_RESPONSE)
- .add(GET_OPERATION_RESPONSE)
+ .add(GET_GLOBAL_OPERATION_RESPONSE)
.add(GET_NETWORK_RESPONSE)
.add(HttpResponse.builder().statusCode(404).build())
.add(SUCESSFULL_OPERATION_RESPONSE)
- .add(GET_OPERATION_RESPONSE)
+ .add(GET_GLOBAL_OPERATION_RESPONSE)
.add(LIST_INSTANCES_RESPONSE)
.add(LIST_PROJECT_IMAGES_RESPONSE)
.add(LIST_GOOGLE_IMAGES_RESPONSE)
- .add(LIST_ZONES_RESPONSE)
.add(LIST_MACHINE_TYPES_RESPONSE)
.add(SUCESSFULL_OPERATION_RESPONSE)
- .add(GET_OPERATION_RESPONSE)
+ .add(GET_ZONE_OPERATION_RESPONSE)
+ .add(getInstanceResponse)
+ .add(SET_TAGS_RESPONSE)
+ .add(GET_ZONE_OPERATION_RESPONSE)
.add(getInstanceResponse)
- .add(LIST_PROJECT_IMAGES_RESPONSE)
- .add(LIST_GOOGLE_IMAGES_RESPONSE)
- .add(LIST_ZONES_RESPONSE)
- .add(LIST_MACHINE_TYPES_RESPONSE)
.build();
ComputeService computeService = orderedRequestsSendResponses(orderedRequests, orderedResponses);
GoogleComputeEngineTemplateOptions options = computeService.templateOptions().as(GoogleComputeEngineTemplateOptions.class);
-
+ options.tags(ImmutableSet.of("aTag"));
getOnlyElement(computeService.createNodesInGroup("test", 1, options));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
index 2b76322..fbcd355 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
@@ -58,7 +58,7 @@ public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTe
@Test(enabled = true, dependsOnMethods = "testReboot")
public void testSuspendResume() throws Exception {
}
-
+
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
public void testListNodesByIds() throws Exception {
super.testGetNodesWithDetails();
@@ -76,7 +76,7 @@ public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTe
super.testListNodes();
}
- @Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails", "testListNodesByIds" })
+ @Test(enabled = true, dependsOnMethods = {"testListNodes", "testGetNodesWithDetails", "testListNodesByIds"})
@Override
public void testDestroyNodes() {
super.testDestroyNodes();
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
index f8301a2..1d1104f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
@@ -16,14 +16,14 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.googlecomputeengine.domain.Image;
-import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertSame;
import java.net.URI;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertSame;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.googlecomputeengine.domain.Image;
+import org.testng.annotations.Test;
/**
* @author David Alves
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java
index be998b6..40de63e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java
@@ -16,10 +16,14 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
import org.easymock.EasyMock;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.domain.ComputeMetadata;
@@ -28,13 +32,10 @@ import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.googlecomputeengine.compute.predicates.AllNodesInGroupTerminated;
import org.testng.annotations.Test;
-import java.util.Set;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.testng.Assert.assertSame;
-import static org.testng.Assert.assertTrue;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
/**
* @author David Alves
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
new file mode 100644
index 0000000..5ec5be9
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
@@ -0,0 +1,166 @@
+/*
+ * 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.features;
+
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertNull;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.parse.ParseAddressListTest;
+import org.jclouds.googlecomputeengine.parse.ParseAddressTest;
+import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+/**
+ * @author David Alves
+ */
+@Test(groups = "unit")
+public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+ public void testGetAddressResponseIs2xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/address_get.json")).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getAddressApiForProject("myproject");
+
+ assertEquals(api.getInRegion("us-central1", "test-ip1"),
+ new ParseAddressTest().expected());
+ }
+
+ public void testGetAddressResponseIs4xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getAddressApiForProject("myproject");
+
+ assertNull(api.getInRegion("us-central1", "test-ip1"));
+ }
+
+ public void testInsertAddressResponseIs2xx() {
+ HttpRequest insert = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://www.googleapis.com/compute/v1beta15/projects/myproject/regions/us-central1/addresses")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN)
+ .payload(payloadFromResourceWithContentType("/address_insert.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse insertAddressResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/region_operation.json")).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, insert,
+ insertAddressResponse).getAddressApiForProject("myproject");
+
+ assertEquals(api.createInRegion("us-central1", "test-ip1"), new ParseOperationTest().expected());
+ }
+
+ public void testDeleteAddressResponseIs2xx() {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1beta15/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/region_operation.json")).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, deleteResponse).getAddressApiForProject("myproject");
+
+ assertEquals(api.deleteInRegion("us-central1", "test-ip1"),
+ new ParseOperationTest().expected());
+ }
+
+ public void testDeleteAddressResponseIs4xx() {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1beta15/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, deleteResponse).getAddressApiForProject("myproject");
+
+ assertNull(api.deleteInRegion("us-central1", "test-ip1"));
+ }
+
+ public void testListAddresssResponseIs2xx() {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1beta15/projects/myproject/regions/us-central1/addresses")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/address_list.json")).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, list, operationResponse).getAddressApiForProject("myproject");
+
+ assertEquals(api.listFirstPageInRegion("us-central1").toString(),
+ new ParseAddressListTest().expected().toString());
+ }
+
+ public void testListAddresssResponseIs4xx() {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1beta15/projects/myproject/regions/us-central1/addresses")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, list, operationResponse).getAddressApiForProject("myproject");
+
+ assertTrue(api.listInRegion("us-central1").concat().isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
new file mode 100644
index 0000000..356106f
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.domain.Address;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Andrew Bayer
+ */
+public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private static final String ADDRESS_NAME = "address-api-live-test-address";
+ private static final int TIME_WAIT = 30;
+
+ private AddressApi api() {
+ return api.getAddressApiForProject(userProject.get());
+ }
+
+ @Test(groups = "live")
+ public void testInsertAddress() {
+
+ assertRegionOperationDoneSucessfully(api().createInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME), TIME_WAIT);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testInsertAddress")
+ public void testGetAddress() {
+ Address address = api().getInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME);
+ assertNotNull(address);
+ assertEquals(address.getName(), ADDRESS_NAME);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testGetAddress")
+ public void testListAddress() {
+
+ PagedIterable<Address> addresss = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
+ .filter("name eq " + ADDRESS_NAME));
+
+ List<Address> addresssAsList = Lists.newArrayList(addresss.concat());
+
+ assertEquals(addresssAsList.size(), 1);
+
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testListAddress")
+ public void testDeleteAddress() {
+
+ assertRegionOperationDoneSucessfully(api().deleteInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME), TIME_WAIT);
+ }
+}