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:59 UTC
[10/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/compute/functions/MachineTypeToHardware.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeToHardware.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeToHardware.java
deleted file mode 100644
index 410c7ea..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeToHardware.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.compute.functions;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.HardwareBuilder;
-import org.jclouds.compute.domain.Processor;
-import org.jclouds.compute.domain.Volume;
-import org.jclouds.compute.domain.internal.VolumeImpl;
-import org.jclouds.googlecomputeengine.domain.MachineType;
-
-/**
- * Transforms a google compute domain specific machine type to a generic Hardware object.
- *
- * @author David Alves
- */
-public class MachineTypeToHardware implements Function<MachineType, Hardware> {
-
- @Override
- public Hardware apply(MachineType input) {
- return new HardwareBuilder()
- .id(input.getName())
- .name(input.getName())
- .hypervisor("kvm")
- .processor(new Processor(input.getGuestCpus(), 1.0))
- .providerId(input.getId())
- .ram(input.getMemoryMb())
- .uri(input.getSelfLink())
- .volumes(collectVolumes(input))
- .build();
- }
-
- private Iterable<Volume> collectVolumes(MachineType input) {
- ImmutableSet.Builder<Volume> volumes = ImmutableSet.builder();
- for (MachineType.EphemeralDisk disk : input.getEphemeralDisks()) {
- volumes.add(new VolumeImpl(null, Volume.Type.LOCAL, new Integer(disk.getDiskGb()).floatValue(), null, true,
- false));
- }
- return volumes.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodes.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodes.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodes.java
index 9314298..f919697 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodes.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodes.java
@@ -16,14 +16,16 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Sets;
-import org.jclouds.compute.domain.NodeMetadata;
+import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
-import java.util.Set;
+
+import org.jclouds.compute.domain.NodeMetadata;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+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/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
new file mode 100644
index 0000000..c878688
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
@@ -0,0 +1,47 @@
+/*
+ * 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.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GOOGLE_PROVIDER_LOCATION;
+
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.googlecomputeengine.domain.Region;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Transforms a google compute domain specific region to a generic Region object.
+ *
+ * @author David Alves
+ */
+public class RegionToLocation implements Function<Region, Location> {
+
+ @Override
+ public Location apply(Region input) {
+ return new LocationBuilder()
+ .description(input.getDescription().orNull())
+ .metadata(ImmutableMap.of("selfLink", (Object) checkNotNull(input.getSelfLink(), "region URI")))
+ .id(input.getName())
+ .scope(LocationScope.REGION)
+ .parent(GOOGLE_PROVIDER_LOCATION)
+ .build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
index 56dde56..be2df66 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
@@ -16,15 +16,16 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GOOGLE_PROVIDER_LOCATION;
+
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.googlecomputeengine.domain.Zone;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GOOGLE_PROVIDER_LOCATION;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
/**
* Transforms a google compute domain specific zone to a generic Zone object.
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
index 9d74d3c..b5d74ed 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
@@ -16,19 +16,20 @@
*/
package org.jclouds.googlecomputeengine.compute.options;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.scriptbuilder.domain.Statement;
+import static com.google.common.base.Optional.fromNullable;
+import static org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
import java.net.URI;
import java.util.Map;
import java.util.Set;
-import static com.google.common.base.Optional.fromNullable;
-import static org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.scriptbuilder.domain.Statement;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
/**
* Instance options specific to Google Compute Engine.
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
index 72d0371..a52f9b0 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
@@ -16,12 +16,6 @@
*/
package org.jclouds.googlecomputeengine.compute.predicates;
-import com.google.common.base.Predicate;
-import org.jclouds.compute.ComputeService;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.all;
import static com.google.common.collect.Sets.filter;
@@ -29,6 +23,13 @@ import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.all;
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.compute.ComputeService;
+
+import com.google.common.base.Predicate;
+
/**
* @author David Alves
*/
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
index b680607..5380313 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
@@ -16,12 +16,21 @@
*/
package org.jclouds.googlecomputeengine.compute.strategy;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.collect.ImmutableSet.of;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
+import static org.jclouds.util.Predicates2.retry;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata;
@@ -38,19 +47,12 @@ import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
-import javax.inject.Inject;
-import javax.inject.Named;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.ImmutableSet.of;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
-import static org.jclouds.util.Predicates2.retry;
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
/**
* @author David Alves
@@ -78,7 +80,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
GoogleComputeEngineApi api,
@UserProject Supplier<String> userProject,
- Predicate<AtomicReference<Operation>> operationDonePredicate,
+ @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
@Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
@Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout) {
super(addNodeWithGroupStrategy, listNodesStrategy, namingConvention, userExecutor,
@@ -127,7 +129,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
if (network != null) {
return network;
} else if (templateOptions.getNetwork().isPresent()) {
- throw new IllegalArgumentException("requested network " + networkName + " does not exist");
+ throw new IllegalArgumentException("requested network " + networkName + " does not exist");
}
AtomicReference<Operation> operation = new AtomicReference<Operation>(api.getNetworkApiForProject(userProject
@@ -135,7 +137,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
MILLISECONDS).apply(operation);
- checkState(!operation.get().getHttpError().isPresent(),"Could not create network, operation failed" + operation);
+ checkState(!operation.get().getHttpError().isPresent(), "Could not create network, operation failed" + operation);
return checkNotNull(api.getNetworkApiForProject(userProject.get()).get(sharedResourceName),
"no network with name %s was found", sharedResourceName);
@@ -186,7 +188,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
MILLISECONDS).apply(operation);
- checkState(!operation.get().getHttpError().isPresent(),"Could not create firewall, operation failed" + operation);
+ checkState(!operation.get().getHttpError().isPresent(), "Could not create firewall, operation failed" + operation);
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
index 38cfcf0..cdae3c4 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
@@ -16,19 +16,21 @@
*/
package org.jclouds.googlecomputeengine.compute.strategy;
-import com.google.inject.Inject;
-import org.jclouds.compute.domain.TemplateBuilderSpec;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.ssh.internal.RsaSshKeyPairGenerator;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.inject.Singleton;
-import java.security.NoSuchAlgorithmException;
-import java.util.Map;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
+import org.jclouds.compute.domain.TemplateBuilderSpec;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ssh.internal.RsaSshKeyPairGenerator;
+
+import com.google.inject.Inject;
/**
* @author David Alves
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
index dcad62c..d774b55 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
@@ -16,15 +16,16 @@
*/
package org.jclouds.googlecomputeengine.compute.strategy;
-import com.google.common.base.Function;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.domain.LoginCredentials;
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Function;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
/**
* GCE needs the credentials to create the node so the node credentials already take the Image credentials into account,
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/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 6c393f4..31f3786 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
@@ -18,8 +18,11 @@ package org.jclouds.googlecomputeengine.config;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Suppliers.compose;
+import static com.google.inject.name.Names.named;
+import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.net.URI;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
@@ -28,8 +31,12 @@ import javax.inject.Singleton;
import org.jclouds.domain.Credentials;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.Project;
+import org.jclouds.googlecomputeengine.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.handlers.GoogleComputeEngineErrorHandler;
-import org.jclouds.googlecomputeengine.predicates.OperationDonePredicate;
+import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
+import org.jclouds.googlecomputeengine.predicates.RegionOperationDonePredicate;
+import org.jclouds.googlecomputeengine.predicates.ZoneOperationDonePredicate;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.Uris;
import org.jclouds.http.annotation.ClientError;
@@ -38,8 +45,12 @@ import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.Provider;
+import org.jclouds.location.suppliers.ImplicitLocationSupplier;
+import org.jclouds.location.suppliers.implicit.FirstZone;
+import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.rest.config.HttpApiModule;
+import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
@@ -47,6 +58,7 @@ import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.inject.Provides;
+import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
@@ -62,7 +74,13 @@ public class GoogleComputeEngineHttpApiModule extends HttpApiModule<GoogleComput
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
- bind(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {}).to(OperationDonePredicate.class);
+ bind(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
+ }).annotatedWith(named("global")).to(GlobalOperationDonePredicate.class);
+ bind(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
+ }).annotatedWith(named("region")).to(RegionOperationDonePredicate.class);
+ bind(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
+ }).annotatedWith(named("zone")).to(ZoneOperationDonePredicate.class);
+ bind(ImplicitLocationSupplier.class).to(FirstZone.class).in(Scopes.SINGLETON);
super.configure();
}
@@ -76,54 +94,76 @@ public class GoogleComputeEngineHttpApiModule extends HttpApiModule<GoogleComput
@Provides
@Singleton
@UserProject
- public Supplier<String> supplyProject(@org.jclouds.location.Provider final Supplier<Credentials> creds) {
- return compose(new Function<Credentials, String>() {
- public String apply(Credentials in) {
- checkState(in.identity.indexOf("@") != 1, "identity should be in project_id@developer.gserviceaccount.com" +
- " format");
- return Iterables.get(Splitter.on("@").split(in.identity), 0);
- }
- }, creds);
+ public Supplier<String> supplyProject(@Provider final Supplier<Credentials> creds,
+ final GoogleComputeEngineApi api,
+ AtomicReference<AuthorizationException> authException,
+ @Named(PROPERTY_SESSION_INTERVAL) long seconds) {
+ return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
+ compose(new Function<Credentials, String>() {
+ public String apply(Credentials in) {
+ checkState(in.identity.indexOf("@") != 1,
+ "identity should be in project_id@developer.gserviceaccount.com format");
+
+ Project project = api.getProjectApi().get(Iterables.get(Splitter.on("@").split(in.identity), 0));
+ return project.getName();
+ }
+ }, creds), seconds, TimeUnit.SECONDS);
}
@Provides
@Singleton
- @Named("machineTypes")
+ @Named("machineTypeToURI")
public Function<String, URI> provideMachineTypeNameToURIFunction(final @Provider Supplier<URI> endpoint,
final @UserProject 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
- ("/machineTypes/").appendPath(input).build();
+ SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(input);
+ return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
+ .appendPath("/zones/").appendPath(slashEncodedIds.getFirstId())
+ .appendPath("/machineTypes/").appendPath(slashEncodedIds.getSecondId()).build();
}
};
}
@Provides
@Singleton
- @Named("networks")
+ @Named("networkToURI")
public Function<String, URI> provideNetworkNameToURIFunction(final @Provider Supplier<URI> endpoint,
final @UserProject 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
- ("/networks/").appendPath(input).build();
+ return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
+ .appendPath("/global/networks/").appendPath(input).build();
}
};
}
@Provides
@Singleton
- @Named("zones")
+ @Named("zoneToURI")
public Function<String, URI> provideZoneNameToURIFunction(final @Provider Supplier<URI> endpoint,
final @UserProject 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
- ("/zones/").appendPath(input).build();
+ return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
+ .appendPath("/zones/").appendPath(input).build();
+ }
+ };
+ }
+
+ @Provides
+ @Singleton
+ @Named("regionToURI")
+ public Function<String, URI> provideRegionNameToURIFunction(final @Provider Supplier<URI> endpoint,
+ final @UserProject 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("/regions/").appendPath(input).build();
}
};
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
index 28ac2ea..1378a80 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
@@ -16,7 +16,31 @@
*/
package org.jclouds.googlecomputeengine.config;
-import com.google.common.collect.ForwardingMap;
+import static org.jclouds.googlecomputeengine.domain.Firewall.Rule;
+
+import java.beans.ConstructorProperties;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Singleton;
+
+import org.jclouds.googlecomputeengine.domain.Firewall;
+import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
+import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.Project;
+import org.jclouds.googlecomputeengine.options.FirewallOptions;
+import org.jclouds.googlecomputeengine.options.RouteOptions;
+import org.jclouds.json.config.GsonModule;
+import org.jclouds.oauth.v2.domain.ClaimSet;
+import org.jclouds.oauth.v2.domain.Header;
+import org.jclouds.oauth.v2.json.ClaimSetTypeAdapter;
+import org.jclouds.oauth.v2.json.HeaderTypeAdapter;
+
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Range;
import com.google.gson.JsonArray;
@@ -30,27 +54,6 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
-import org.jclouds.googlecomputeengine.domain.Firewall;
-import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.Project;
-import org.jclouds.googlecomputeengine.options.FirewallOptions;
-import org.jclouds.json.config.GsonModule;
-import org.jclouds.oauth.v2.domain.ClaimSet;
-import org.jclouds.oauth.v2.domain.Header;
-import org.jclouds.oauth.v2.json.ClaimSetTypeAdapter;
-import org.jclouds.oauth.v2.json.HeaderTypeAdapter;
-
-import javax.inject.Singleton;
-import java.beans.ConstructorProperties;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-
-import static org.jclouds.googlecomputeengine.domain.Firewall.Rule;
/**
* @author David Alves
@@ -74,6 +77,7 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
.put(Instance.class, new InstanceTypeAdapter())
.put(InstanceTemplate.class, new InstanceTemplateTypeAdapter())
.put(FirewallOptions.class, new FirewallOptionsTypeAdapter())
+ .put(RouteOptions.class, new RouteOptionsTypeAdapter())
.put(Rule.class, new RuleTypeAdapter())
.build();
}
@@ -81,7 +85,7 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
/**
* Parser for operations that unwraps errors avoiding an extra intermediate object.
*
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/operations"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/operations"/>
*/
@Singleton
private static class OperationTypeAdapter implements JsonDeserializer<Operation> {
@@ -107,16 +111,16 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "targetLink", "targetId",
"clientOperationId", "status", "statusMessage", "user", "progress", "insertTime", "startTime",
- "endTime", "httpErrorStatusCode", "httpErrorMessage", "operationType"
+ "endTime", "httpErrorStatusCode", "httpErrorMessage", "operationType", "region", "zone"
})
private OperationInternal(String id, Date creationTimestamp, URI selfLink, String name,
String description, URI targetLink, String targetId, String clientOperationId,
Status status, String statusMessage, String user, int progress, Date insertTime,
Date startTime, Date endTime, int httpErrorStatusCode, String httpErrorMessage,
- String operationType) {
+ String operationType, URI region, URI zone) {
super(id, creationTimestamp, selfLink, name, description, targetLink, targetId, clientOperationId,
status, statusMessage, user, progress, insertTime, startTime, endTime, httpErrorStatusCode,
- httpErrorMessage, operationType, null);
+ httpErrorMessage, operationType, null, region, zone);
}
}
}
@@ -149,8 +153,11 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
// deal with metadata
if (src.getMetadata() != null && !src.getMetadata().isEmpty()) {
- JsonObject metadata = (JsonObject) context.serialize(new Metadata(src.getMetadata()));
- instance.add("metadata", metadata);
+ Metadata metadata = Metadata.builder()
+ .items(src.getMetadata())
+ .build();
+ JsonObject metadataJson = (JsonObject) context.serialize(metadata);
+ instance.add("metadata", metadataJson);
return instance;
}
@@ -162,9 +169,7 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
super(template.getMachineType());
name(template.getName());
description(template.getDescription());
- zone(template.getZone());
image(template.getImage());
- tags(template.getTags());
serviceAccounts(template.getServiceAccounts());
networkInterfaces(template.getNetworkInterfaces());
}
@@ -205,7 +210,7 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
"status", "statusMessage", "zone", "networkInterfaces", "metadata", "serviceAccounts"
})
private InstanceInternal(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Set<String> tags, URI image, URI machineType, Status status, String statusMessage,
+ Tags tags, URI image, URI machineType, Status status, String statusMessage,
URI zone, Set<NetworkInterface> networkInterfaces, Metadata metadata,
Set<ServiceAccount> serviceAccounts) {
super(id, creationTimestamp, selfLink, name, description, tags, image, machineType,
@@ -233,7 +238,11 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
builder.put(object.get("key").getAsString(), object.get("value").getAsString());
}
}
- return new Metadata(builder.build());
+ String fingerprint = null;
+ if (metadata.getAsJsonPrimitive("fingerprint") != null) {
+ fingerprint = metadata.getAsJsonPrimitive("fingerprint").getAsString();
+ }
+ return new Metadata(fingerprint, builder.build());
}
@Override
@@ -241,30 +250,21 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
JsonObject metadataObject = new JsonObject();
metadataObject.add("kind", new JsonPrimitive("compute#metadata"));
JsonArray items = new JsonArray();
- for (Map.Entry<String, String> entry : src.entrySet()) {
+ for (Map.Entry<String, String> entry : src.getItems().entrySet()) {
JsonObject object = new JsonObject();
object.addProperty("key", entry.getKey());
object.addProperty("value", entry.getValue());
items.add(object);
}
metadataObject.add("items", items);
+ if (src.getFingerprint() != null) {
+ metadataObject.addProperty("fingerprint", src.getFingerprint());
+ }
return metadataObject;
}
}
- public static class Metadata extends ForwardingMap<String, String> {
- private final Map<String, String> delegate;
-
- public Metadata(Map<String, String> delegate) {
- this.delegate = delegate;
- }
-
- @Override
- protected Map<String, String> delegate() {
- return delegate;
- }
- }
@Singleton
private static class ProjectTypeAdapter implements JsonDeserializer<Project> {
@@ -322,6 +322,46 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
}
}
+ @Singleton
+ private static class RouteOptionsTypeAdapter implements JsonSerializer<RouteOptions> {
+
+ @Override
+ public JsonElement serialize(RouteOptions src, Type typeOfSrc, JsonSerializationContext context) {
+ JsonObject route = new JsonObject();
+ if (src.getName() != null) {
+ route.addProperty("name", src.getName());
+ }
+ if (src.getNetwork() != null) {
+ route.addProperty("network", src.getNetwork().toString());
+ }
+ if (src.getNextHopGateway() != null) {
+ route.addProperty("nextHopGateway", src.getNextHopGateway().toString());
+ }
+ if (src.getNextHopInstance() != null) {
+ route.addProperty("nextHopInstance", src.getNextHopInstance().toString());
+ }
+ if (src.getNextHopNetwork() != null) {
+ route.addProperty("nextHopNetwork", src.getNextHopNetwork().toString());
+ }
+ if (src.getDestRange() != null) {
+ route.addProperty("destRange", src.getDestRange());
+ }
+ if (src.getDescription() != null) {
+ route.addProperty("description", src.getDescription());
+ }
+ if (src.getPriority() != null) {
+ route.addProperty("priority", src.getPriority());
+ }
+ if (src.getNextHopIp() != null) {
+ route.addProperty("nextHopIp", src.getNextHopIp());
+ }
+ if (!src.getTags().isEmpty()) {
+ route.add("tags", buildArrayOfStrings(src.getTags()));
+ }
+ return route;
+ }
+ }
+
private static JsonArray buildArrayOfStrings(Set<String> strings) {
JsonArray array = new JsonArray();
for (String string : strings) {
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
index fa62625..f287fff 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
@@ -16,9 +16,6 @@
*/
package org.jclouds.googlecomputeengine.config;
-import com.google.common.base.Function;
-import com.google.common.base.Supplier;
-import com.google.inject.TypeLiteral;
import org.jclouds.oauth.v2.config.OAuthModule;
import org.jclouds.oauth.v2.domain.OAuthCredentials;
import org.jclouds.oauth.v2.domain.Token;
@@ -29,6 +26,10 @@ import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier;
import org.jclouds.oauth.v2.functions.SignOrProduceMacForToken;
import org.jclouds.rest.internal.GeneratedHttpRequest;
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.inject.TypeLiteral;
+
/**
* Overrides OAuthModule leaving TypeAdapters bindings out.
* <p/>
@@ -40,9 +41,13 @@ public class OAuthModuleWithoutTypeAdapters extends OAuthModule {
@Override
protected void configure() {
- bind(new TypeLiteral<Function<byte[], byte[]>>() {}).to(SignOrProduceMacForToken.class);
- bind(new TypeLiteral<Supplier<OAuthCredentials>>() {}).to(OAuthCredentialsSupplier.class);
- bind(new TypeLiteral<Function<GeneratedHttpRequest, TokenRequest>>() {}).to(BuildTokenRequest.class);
- bind(new TypeLiteral<Function<TokenRequest, Token>>() {}).to(FetchToken.class);
+ bind(new TypeLiteral<Function<byte[], byte[]>>() {
+ }).to(SignOrProduceMacForToken.class);
+ bind(new TypeLiteral<Supplier<OAuthCredentials>>() {
+ }).to(OAuthCredentialsSupplier.class);
+ bind(new TypeLiteral<Function<GeneratedHttpRequest, TokenRequest>>() {
+ }).to(BuildTokenRequest.class);
+ bind(new TypeLiteral<Function<TokenRequest, Token>>() {
+ }).to(FetchToken.class);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
index 1fe04bc..226d6a1 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
@@ -16,12 +16,13 @@
*/
package org.jclouds.googlecomputeengine.config;
-import javax.inject.Qualifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import javax.inject.Qualifier;
+
/**
* Qualifies a property as the user's project id.
*
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
new file mode 100644
index 0000000..fda65ec
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
@@ -0,0 +1,122 @@
+/*
+ * 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.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Date;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+
+/**
+ * A persistent disk resource
+ *
+ * @author David Alves
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/disks"/>
+ */
+@Beta
+public abstract class AbstractDisk extends Resource {
+
+ protected final Integer sizeGb;
+ protected final String status;
+
+ protected AbstractDisk(Kind kind, String id, Date creationTimestamp, URI selfLink, String name, String description,
+ Integer sizeGb, String status) {
+ super(kind, id, creationTimestamp, selfLink, name, description);
+ this.sizeGb = checkNotNull(sizeGb, "sizeGb of %s", name);
+ this.status = checkNotNull(status, "status of %s", name);
+ }
+
+ /**
+ * @return size of the persistent disk, specified in GB.
+ */
+ public int getSizeGb() {
+ return sizeGb;
+ }
+
+ /**
+ * @return the status of disk creation.
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Objects.ToStringHelper string() {
+ return super.string()
+ .omitNullValues()
+ .add("sizeGb", sizeGb)
+ .add("status", status);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return string().toString();
+ }
+
+ public static Builder<?> builder() {
+ return new ConcreteBuilder();
+ }
+
+ public Builder<?> toBuilder() {
+ return new ConcreteBuilder().fromAbstractDisk(this);
+ }
+
+ public abstract static class Builder<T extends Builder<T>> extends Resource.Builder<T> {
+
+ protected Integer sizeGb;
+ protected String status;
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.AbstractDisk#getSizeGb()
+ */
+ public T sizeGb(Integer sizeGb) {
+ this.sizeGb = sizeGb;
+ return self();
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.AbstractDisk#getStatus()
+ */
+ public T status(String status) {
+ this.status = status;
+ return self();
+ }
+
+ public T fromAbstractDisk(AbstractDisk in) {
+ return super.fromResource(in)
+ .sizeGb(in.getSizeGb())
+ .status(in.getStatus());
+ }
+
+ }
+
+ private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
+ @Override
+ protected ConcreteBuilder self() {
+ 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/domain/Address.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
new file mode 100644
index 0000000..7f97ec0
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
@@ -0,0 +1,178 @@
+/*
+ * 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.domain;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.beans.ConstructorProperties;
+import java.net.URI;
+import java.util.Date;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+
+/**
+ * Represents an Address resource.
+ *
+ * @author Andrew Bayer
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/addresses"/>
+ */
+@Beta
+public final class Address extends Resource {
+
+ private final String status;
+ private final Optional<URI> user;
+ private final URI region;
+ private final String address;
+
+ @ConstructorProperties({
+ "id", "creationTimestamp", "selfLink", "name", "description", "status", "user",
+ "region", "address"
+ })
+ private Address(String id, Date creationTimestamp, URI selfLink, String name, String description,
+ String status, URI user, URI region, String address) {
+ super(Kind.ADDRESS, id, creationTimestamp, selfLink, name, description);
+ this.status = checkNotNull(status, "status of %s", name);
+ this.user = fromNullable(user);
+ this.region = checkNotNull(region, "region of %s", name);
+ this.address = checkNotNull(address, "address of %s", name);
+ }
+
+ /**
+ * @return The status of the address. Valid items are RESERVED and IN USE.
+ * A reserved address is currently available to the project and can be
+ * used by a resource. An in-use address is currently being used by a resource.
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * @return URL of the resource currently using this address.
+ */
+ public Optional<URI> getUser() {
+ return user;
+ }
+
+ /**
+ * @return URL of the region where the address resides.
+ */
+ public URI getRegion() {
+ return region;
+ }
+
+ /**
+ * @return The IP address represented by this resource.
+ */
+ public String getAddress() {
+ return address;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Address that = Address.class.cast(obj);
+ return equal(this.kind, that.kind)
+ && equal(this.name, that.name)
+ && equal(this.region, that.region);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Objects.ToStringHelper string() {
+ return super.string()
+ .omitNullValues()
+ .add("status", status)
+ .add("user", user.orNull())
+ .add("region", region)
+ .add("address", address);
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Builder toBuilder() {
+ return new Builder().fromAddress(this);
+ }
+
+ public static final class Builder extends Resource.Builder<Builder> {
+ private String status;
+ private URI user;
+ private URI region;
+ private String address;
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Address#getStatus()
+ */
+ public Builder status(String status) {
+ this.status = status;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Address#getUser()
+ */
+ public Builder user(URI user) {
+ this.user = user;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Address#getRegion()
+ */
+ public Builder region(URI region) {
+ this.region = region;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Address#getAddress()
+ */
+ public Builder address(String address) {
+ this.address = address;
+ return this;
+ }
+
+ @Override
+ protected Builder self() {
+ return this;
+ }
+
+ public Address build() {
+ return new Address(super.id, super.creationTimestamp, super.selfLink, super.name,
+ super.description, status, user, region, address);
+ }
+
+ public Builder fromAddress(Address in) {
+ return super.fromResource(in)
+ .status(in.getStatus())
+ .user(in.getUser().orNull())
+ .region(in.getRegion())
+ .address(in.getAddress());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
new file mode 100644
index 0000000..8dc6b76
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
@@ -0,0 +1,197 @@
+/*
+ * 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.domain;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Optional.fromNullable;
+
+import java.beans.ConstructorProperties;
+import java.net.URI;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+
+/**
+ * Deprecation information for an image or kernel
+ *
+ * @author Andrew Bayer
+ */
+public class Deprecated {
+ private final Optional<String> state;
+ private final Optional<URI> replacement;
+ private final Optional<String> deprecated;
+ private final Optional<String> obsolete;
+ private final Optional<String> deleted;
+
+ @ConstructorProperties({"state", "replacement", "deprecated", "obsolete", "deleted"})
+ public Deprecated(String state, URI replacement, String deprecated, String obsolete,
+ String deleted) {
+ this.state = fromNullable(state);
+ this.replacement = fromNullable(replacement);
+ this.deprecated = fromNullable(deprecated);
+ this.obsolete = fromNullable(obsolete);
+ this.deleted = fromNullable(deleted);
+ }
+
+ /**
+ * @return The deprecation state of this image.
+ */
+ public Optional<String> getState() {
+ return state;
+ }
+
+ /**
+ * @return A fully-qualified URL of the suggested replacement for the deprecated image.
+ */
+ public Optional<URI> getReplacement() {
+ return replacement;
+ }
+
+ /**
+ * @return An optional RFC3339 timestamp for when the deprecation state of this resource will be changed to DEPRECATED.
+ */
+ public Optional<String> getDeprecated() {
+ return deprecated;
+ }
+
+ /**
+ * @return An optional RFC3339 timestamp on or after which the deprecation state of this resource will be changed toOBSOLETE.
+ */
+ public Optional<String> getObsolete() {
+ return obsolete;
+ }
+
+ /**
+ * @return An optional RFC3339 timestamp on or after which the deprecation state of this resource will be changed to DELETED.
+ */
+ public Optional<String> getDeleted() {
+ return deleted;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(state, replacement, deprecated, obsolete, deleted);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Deprecated that = Deprecated.class.cast(obj);
+ return equal(this.state, that.state)
+ && equal(this.replacement, that.replacement)
+ && equal(this.deprecated, that.deprecated)
+ && equal(this.obsolete, that.obsolete)
+ && equal(this.deleted, that.deleted);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Objects.ToStringHelper string() {
+ return toStringHelper(this)
+ .omitNullValues()
+ .add("state", state.orNull())
+ .add("replacement", replacement.orNull())
+ .add("deprecated", deprecated.orNull())
+ .add("obsolete", obsolete.orNull())
+ .add("deleted", deleted.orNull());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return string().toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Builder toBuilder() {
+ return builder().fromDeprecated(this);
+ }
+
+ public static class Builder {
+ private String state;
+ private URI replacement;
+ private String deprecated;
+ private String obsolete;
+ private String deleted;
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Deprecated#getState()
+ */
+ public Builder state(String state) {
+ this.state = state;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Deprecated#getReplacement()
+ */
+ public Builder replacement(URI replacement) {
+ this.replacement = replacement;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Deprecated#getDeprecated()
+ */
+ public Builder deprecated(String deprecated) {
+ this.deprecated = deprecated;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Deprecated#getObsolete()
+ */
+ public Builder obsolete(String obsolete) {
+ this.obsolete = obsolete;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Deprecated#getDeprecated()
+ */
+ public Builder deleted(String deleted) {
+ this.deleted = deleted;
+ return this;
+ }
+
+ public Deprecated build() {
+ return new Deprecated(state, replacement, deprecated, obsolete, deleted);
+ }
+
+ public Builder fromDeprecated(Deprecated in) {
+ return new Builder().state(in.getState().orNull())
+ .replacement(in.getReplacement().orNull())
+ .deprecated(in.getDeprecated().orNull())
+ .obsolete(in.getObsolete().orNull())
+ .deleted(in.getDeleted().orNull());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
index a34c32f..df5e38c 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
@@ -16,27 +16,26 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
/**
* A persistent disk resource
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/disks"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/disks"/>
*/
@Beta
-public final class Disk extends Resource {
+public final class Disk extends AbstractDisk {
- private final Integer sizeGb;
private final URI zone;
- private final String status;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "sizeGb", "zone",
@@ -44,17 +43,8 @@ public final class Disk extends Resource {
})
private Disk(String id, Date creationTimestamp, URI selfLink, String name, String description,
Integer sizeGb, URI zone, String status) {
- super(Kind.DISK, id, creationTimestamp, selfLink, name, description);
- this.sizeGb = checkNotNull(sizeGb, "sizeGb of %s", name);
+ super(Kind.DISK, id, creationTimestamp, selfLink, name, description, sizeGb, status);
this.zone = checkNotNull(zone, "zone of %s", name);
- this.status = checkNotNull(status, "status of %s", name);
- }
-
- /**
- * @return size of the persistent disk, specified in GB.
- */
- public int getSizeGb() {
- return sizeGb;
}
/**
@@ -65,10 +55,16 @@ public final class Disk extends Resource {
}
/**
- * @return the status of disk creation.
+ * {@inheritDoc}
*/
- public String getStatus() {
- return status;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Disk that = Disk.class.cast(obj);
+ return equal(this.kind, that.kind)
+ && equal(this.name, that.name)
+ && equal(this.zone, that.zone);
}
/**
@@ -77,9 +73,7 @@ public final class Disk extends Resource {
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
- .add("sizeGb", sizeGb)
- .add("zone", zone)
- .add("status", status);
+ .add("zone", zone);
}
/**
@@ -98,19 +92,9 @@ public final class Disk extends Resource {
return new Builder().fromDisk(this);
}
- public static final class Builder extends Resource.Builder<Builder> {
+ public static final class Builder extends AbstractDisk.Builder<Builder> {
- private Integer sizeGb;
- private URI zone;;
- private String status;
-
- /**
- * @see Disk#getSizeGb()
- */
- public Builder sizeGb(Integer sizeGb) {
- this.sizeGb = sizeGb;
- return this;
- }
+ private URI zone;
/**
* @see Disk#getZone()
@@ -120,15 +104,6 @@ public final class Disk extends Resource {
return this;
}
- /**
- * @see Disk#getStatus()
- */
- public Builder status(String status) {
- this.status = status;
- return this;
- }
-
-
@Override
protected Builder self() {
return this;
@@ -136,14 +111,12 @@ public final class Disk extends Resource {
public Disk build() {
return new Disk(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, sizeGb, zone, status);
+ super.description, super.sizeGb, zone, super.status);
}
public Builder fromDisk(Disk in) {
- return super.fromResource(in)
- .sizeGb(in.getSizeGb())
- .zone(in.getZone())
- .status(in.getStatus());
+ return super.fromAbstractDisk(in)
+ .zone(in.getZone());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
index 141936e..52d51ab 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
@@ -16,17 +16,6 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.RangeSet;
-import com.google.common.collect.TreeRangeSet;
-
-import java.beans.ConstructorProperties;
-import java.net.URI;
-import java.util.Date;
-import java.util.Set;
-
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -34,11 +23,22 @@ import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Range.closed;
import static com.google.common.collect.Range.singleton;
+import java.beans.ConstructorProperties;
+import java.net.URI;
+import java.util.Date;
+import java.util.Set;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.TreeRangeSet;
+
/**
* Represents a network firewall
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/firewalls"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/firewalls"/>
* @see <a href="https://developers.google.com/compute/docs/networking#firewalls"/>
*/
@Beta
@@ -83,7 +83,7 @@ public final class Firewall extends Resource {
}
/**
- * @return a list of instance tags which this rule applies to. One or both of sourceRanges and sourceTags may be
+ * @return a list of instance items which this rule applies to. One or both of sourceRanges and sourceTags may be
* set; an inbound connection is allowed if either the range or the tag of the source matches.
*/
public Set<String> getSourceTags() {
@@ -93,7 +93,7 @@ public final class Firewall extends Resource {
/**
* If no targetTags are specified, the firewall rule applies to all instances on the specified network.
*
- * @return a list of instance tags indicating sets of instances located on network which may make network
+ * @return a list of instance items indicating sets of instances located on network which may make network
* connections as specified in allowed.
*/
public Set<String> getTargetTags() {
@@ -241,7 +241,7 @@ public final class Firewall extends Resource {
* permitted connection.
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/firewalls"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/firewalls"/>
*/
public static final class Rule {
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
index d521bbb..8bbfa98 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
@@ -16,24 +16,24 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
/**
* Represents a disk image to use on an instance.
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/images"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/images"/>
*/
@Beta
public final class Image extends Resource {
@@ -41,17 +41,19 @@ public final class Image extends Resource {
private final String sourceType;
private final Optional<URI> preferredKernel;
private final RawDisk rawDisk;
+ private final Optional<Deprecated> deprecated;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "sourceType", "preferredKernel",
- "rawDisk"
+ "rawDisk", "deprecated"
})
protected Image(String id, Date creationTimestamp, URI selfLink, String name, String description,
- String sourceType, URI preferredKernel, RawDisk rawDisk) {
+ String sourceType, URI preferredKernel, RawDisk rawDisk, Deprecated deprecated) {
super(Kind.IMAGE, id, creationTimestamp, selfLink, name, description);
this.sourceType = checkNotNull(sourceType, "sourceType of %s", name);
this.preferredKernel = fromNullable(preferredKernel);
- this.rawDisk = checkNotNull(rawDisk, "rawDisk of %s", name); ;
+ this.rawDisk = checkNotNull(rawDisk, "rawDisk of %s", name);
+ this.deprecated = fromNullable(deprecated);
}
/**
@@ -76,6 +78,13 @@ public final class Image extends Resource {
}
/**
+ * @return the deprecation information for this image
+ */
+ public Optional<Deprecated> getDeprecated() {
+ return deprecated;
+ }
+
+ /**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
@@ -83,7 +92,8 @@ public final class Image extends Resource {
.omitNullValues()
.add("sourceType", sourceType)
.add("preferredKernel", preferredKernel.orNull())
- .add("rawDisk", rawDisk);
+ .add("rawDisk", rawDisk)
+ .add("deprecated", deprecated.orNull());
}
/**
@@ -107,6 +117,7 @@ public final class Image extends Resource {
private String sourceType;
private URI preferredKernel;
private RawDisk rawDisk;
+ private Deprecated deprecated;
/**
* @see Image#getSourceType()
@@ -125,6 +136,14 @@ public final class Image extends Resource {
}
/**
+ * @see Image#getDeprecated()
+ */
+ public Builder deprecated(Deprecated deprecated) {
+ this.deprecated = checkNotNull(deprecated, "deprecated");
+ return this;
+ }
+
+ /**
* @see Image#getRawDisk()
*/
public Builder rawDisk(RawDisk rawDisk) {
@@ -139,14 +158,15 @@ public final class Image extends Resource {
public Image build() {
return new Image(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, sourceType, preferredKernel, rawDisk);
+ super.description, sourceType, preferredKernel, rawDisk, deprecated);
}
public Builder fromImage(Image in) {
return super.fromResource(in)
.sourceType(in.getSourceType())
.preferredKernel(in.getPreferredKernel().orNull())
- .rawDisk(in.getRawDisk());
+ .rawDisk(in.getRawDisk())
+ .deprecated(in.getDeprecated().orNull());
}
}
@@ -155,7 +175,7 @@ public final class Image extends Resource {
* A raw disk image, usually the base for an image.
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/images"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/images"/>
*/
public static class RawDisk {
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-google/blob/53386380/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
index 996d7ec..12b3237 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
@@ -16,29 +16,28 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import org.jclouds.javax.annotation.Nullable;
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
-import java.util.Map;
import java.util.Set;
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
/**
* Represents a virtual machine.
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/instances"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/instances"/>
*/
@Beta
public class Instance extends Resource {
@@ -52,7 +51,7 @@ public class Instance extends Resource {
TERMINATED
}
- protected final Set<String> tags;
+ protected final Tags tags;
protected final URI image;
protected final URI machineType;
protected final Status status;
@@ -60,15 +59,15 @@ public class Instance extends Resource {
protected final URI zone;
protected final Set<NetworkInterface> networkInterfaces;
protected final Set<AttachedDisk> disks;
- protected final Map<String, String> metadata;
+ protected final Metadata metadata;
protected final Set<ServiceAccount> serviceAccounts;
protected Instance(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Set<String> tags, URI image, URI machineType, Status status, String statusMessage,
+ Tags tags, URI image, URI machineType, Status status, String statusMessage,
URI zone, Set<NetworkInterface> networkInterfaces, Set<AttachedDisk> disks,
- Map<String, String> metadata, Set<ServiceAccount> serviceAccounts) {
+ Metadata metadata, Set<ServiceAccount> serviceAccounts) {
super(Kind.INSTANCE, id, creationTimestamp, selfLink, name, description);
- this.tags = tags == null ? ImmutableSet.<String>of() : tags;
+ this.tags = checkNotNull(tags, "tags");
this.image = checkNotNull(image, "image");
this.machineType = checkNotNull(machineType, "machineType of %s", name);
this.status = checkNotNull(status, "status");
@@ -76,7 +75,7 @@ public class Instance extends Resource {
this.zone = checkNotNull(zone, "zone of %s", name);
this.networkInterfaces = networkInterfaces == null ? ImmutableSet.<NetworkInterface>of() : networkInterfaces;
this.disks = disks == null ? ImmutableSet.<AttachedDisk>of() : disks;
- this.metadata = metadata == null ? ImmutableMap.<String, String>of() : metadata;
+ this.metadata = checkNotNull(metadata, "metadata");
this.serviceAccounts = serviceAccounts == null ? ImmutableSet.<ServiceAccount>of() : serviceAccounts;
}
@@ -84,9 +83,9 @@ public class Instance extends Resource {
* Used to identify valid sources or targets for network firewalls. Provided by the client when the instance is
* created. Each tag must be unique, must be 1-63 characters long, and comply with RFC1035.
*
- * @return an optional set of tags applied to this instance.
+ * @return an optional set of items applied to this instance.
*/
- public Set<String> getTags() {
+ public Tags getTags() {
return tags;
}
@@ -147,7 +146,7 @@ public class Instance extends Resource {
/**
* @return metadata for this instance
*/
- public Map<String, String> getMetadata() {
+ public Metadata getMetadata() {
return metadata;
}
@@ -162,10 +161,23 @@ public class Instance extends Resource {
/**
* {@inheritDoc}
*/
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Instance that = Instance.class.cast(obj);
+ return equal(this.kind, that.kind)
+ && equal(this.name, that.name)
+ && equal(this.zone, that.zone);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
- .add("tags", tags)
+ .add("items", tags)
.add("image", image)
.add("machineType", machineType)
.add("status", status)
@@ -195,30 +207,23 @@ public class Instance extends Resource {
public static final class Builder extends Resource.Builder<Builder> {
- private ImmutableSet.Builder<String> tags = ImmutableSet.builder();
+ private Tags tags;
private URI image;
private URI machineType;
private Status status;
private String statusMessage;
private URI zone;
+ private Metadata metadata;
private ImmutableSet.Builder<NetworkInterface> networkInterfaces = ImmutableSet.builder();
private ImmutableSet.Builder<AttachedDisk> disks = ImmutableSet.builder();
- private ImmutableMap.Builder<String, String> metadata = ImmutableMap.builder();
private ImmutableSet.Builder<ServiceAccount> serviceAccounts = ImmutableSet.builder();
- /**
- * @see Instance#getTags()
- */
- public Builder addTag(String tag) {
- this.tags.add(tag);
- return this;
- }
/**
* @see Instance#getTags()
*/
- public Builder tags(Set<String> tags) {
- this.tags.addAll(tags);
+ public Builder tags(Tags tags) {
+ this.tags = tags;
return this;
}
@@ -297,16 +302,8 @@ public class Instance extends Resource {
/**
* @see Instance#getMetadata()
*/
- public Builder metadata(Map<String, String> metadata) {
- this.metadata = new ImmutableMap.Builder<String, String>().putAll(metadata);
- return this;
- }
-
- /**
- * @see Instance#getMetadata()
- */
- public Builder addMetadata(String key, String value) {
- this.metadata.put(checkNotNull(key, "key"), checkNotNull(value, "value of %s", key));
+ public Builder metadata(Metadata metadata) {
+ this.metadata = metadata;
return this;
}
@@ -321,7 +318,7 @@ public class Instance extends Resource {
/**
* @see Instance#getServiceAccounts()
*/
- public Builder serviceAccoutns(Set<ServiceAccount> serviceAccounts) {
+ public Builder serviceAccounts(Set<ServiceAccount> serviceAccounts) {
this.serviceAccounts.addAll(serviceAccounts);
return this;
}
@@ -334,8 +331,8 @@ public class Instance extends Resource {
public Instance build() {
return new Instance(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, tags.build(), image, machineType, status, statusMessage, zone,
- networkInterfaces.build(), disks.build(), metadata.build(), serviceAccounts.build());
+ super.description, tags, image, machineType, status, statusMessage, zone,
+ networkInterfaces.build(), disks.build(), metadata, serviceAccounts.build());
}
public Builder fromInstance(Instance in) {
@@ -349,14 +346,130 @@ public class Instance extends Resource {
.networkInterfaces(in.getNetworkInterfaces())
.disks(in.getDisks())
.metadata(in.getMetadata())
- .serviceAccoutns(in.getServiceAccounts());
+ .serviceAccounts(in.getServiceAccounts());
+ }
+ }
+
+
+
+
+ /**
+ * Tags for an instance, with their fingerprint.
+ */
+ public static class Tags {
+ private final String fingerprint;
+ private final Set<String> items;
+
+ @ConstructorProperties({"fingerprint", "items"})
+ public Tags(String fingerprint, @Nullable Set<String> items) {
+ this.fingerprint = checkNotNull(fingerprint);
+ this.items = items == null ? ImmutableSet.<String>of() : items;
+ }
+
+ /**
+ * Used to identify valid sources or targets for network firewalls. Provided by the client when the instance is
+ * created. Each tag must be unique, must be 1-63 characters long, and comply with RFC1035.
+ *
+ * @return an optional set of items applied to this instance.
+ */
+ public Set<String> getItems() {
+ return items;
+ }
+
+ /**
+ * Gets the fingerprint for the items - needed for updating them.
+ *
+ * @return the fingerprint string for the items.
+ */
+ public String getFingerprint() {
+ return fingerprint;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(fingerprint, items);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ Tags that = Tags.class.cast(obj);
+ return equal(this.items, that.items)
+ && equal(this.fingerprint, that.fingerprint);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Objects.ToStringHelper string() {
+ return toStringHelper(this)
+ .add("items", items)
+ .add("fingerprint", fingerprint);
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return string().toString();
+ }
+
+ public static final class Builder {
+
+ private ImmutableSet.Builder<String> items = ImmutableSet.builder();
+ private String fingerprint;
+
+ /**
+ * @see Tags#getItems()
+ */
+ public Builder addItem(String item) {
+ this.items.add(item);
+ return this;
+ }
+
+ /**
+ * @see Tags#getItems()
+ */
+ public Builder items(Set<String> items) {
+ this.items.addAll(items);
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance.Tags#getFingerprint()
+ */
+ public Builder fingerprint(String fingerprint) {
+ this.fingerprint = fingerprint;
+ return this;
+ }
+
+ public Tags build() {
+ return new Tags(this.fingerprint, this.items.build());
+ }
+
+ public Builder fromTags(Tags in) {
+ return this.fingerprint(in.getFingerprint())
+ .items(in.getItems());
+ }
}
}
/**
* A disk attached to an Instance.
*
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/instances"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/instances"/>
*/
public static class AttachedDisk {
@@ -419,10 +532,9 @@ public class Instance extends Resource {
}
public static class PersistentAttachedDisk extends AttachedDisk {
-
public enum Mode {
READ_WRITE,
- READ_ONLY
+ READ_ONLY;
}
@ConstructorProperties({"mode", "source", "deviceName", "index", "deleteOnTerminate"})
@@ -546,7 +658,7 @@ public class Instance extends Resource {
/**
* A network interface for an Instance.
*
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/instances"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/instances"/>
*/
public static final class NetworkInterface {
@@ -840,7 +952,7 @@ public class Instance extends Resource {
* The output of an instance's serial port;
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/instances/serialPort"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/instances/serialPort"/>
*/
public static final class SerialPortOutput {
@@ -948,7 +1060,7 @@ public class Instance extends Resource {
* A service account for which access tokens are to be made available to the instance through metadata queries.
*
* @author David Alves
- * @see <a href="https://developers.google.com/compute/docs/reference/v1beta13/instances"/>
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1beta15/instances"/>
*/
public static final class ServiceAccount {