You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/19 17:58:21 UTC
[15/17] Initial GCE commit
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
new file mode 100644
index 0000000..0dc1c78
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
@@ -0,0 +1,45 @@
+/*
+ * 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.Zone;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Transforms a google compute domain specific zone to a generic Zone object.
+ */
+public class ZoneToLocation implements Function<Zone, Location> {
+
+ @Override
+ public Location apply(Zone input) {
+ return new LocationBuilder()
+ .description(input.getDescription().orNull())
+ .metadata(ImmutableMap.of("selfLink", (Object) checkNotNull(input.getSelfLink(), "zone URI")))
+ .id(input.getName())
+ .scope(LocationScope.ZONE)
+ .parent(GOOGLE_PROVIDER_LOCATION)
+ .build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java
new file mode 100644
index 0000000..2c84787
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java
@@ -0,0 +1,62 @@
+/*
+ * 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.loaders;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Network;
+import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
+import org.jclouds.logging.Logger;
+
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.common.cache.CacheLoader;
+
+public class FindNetworkOrCreate extends CacheLoader<NetworkAndAddressRange, Network> {
+ @Resource
+ @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+ protected Logger logger = Logger.NULL;
+ protected final GoogleComputeEngineApi api;
+ protected final Function<NetworkAndAddressRange, Network> networkCreator;
+ protected final Supplier<String> userProject;
+
+ @Inject
+ public FindNetworkOrCreate(GoogleComputeEngineApi api,
+ Function<NetworkAndAddressRange, Network> networkCreator,
+ @UserProject Supplier<String> userProject) {
+ this.api = checkNotNull(api, "api");
+ this.networkCreator = checkNotNull(networkCreator, "networkCreator");
+ this.userProject = checkNotNull(userProject, "userProject");
+ }
+
+ @Override
+ public Network load(NetworkAndAddressRange in) {
+ Network network = api.getNetworkApiForProject(userProject.get()).get(in.getName());
+ if (network != null) {
+ return network;
+ } else {
+ return networkCreator.apply(in);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
new file mode 100644
index 0000000..c6aad00
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
@@ -0,0 +1,382 @@
+/*
+ * 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.options;
+
+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 org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk;
+import org.jclouds.scriptbuilder.domain.Statement;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+/**
+ * Instance options specific to Google Compute Engine.
+ */
+public class GoogleComputeEngineTemplateOptions extends TemplateOptions {
+
+ private Optional<URI> network = Optional.absent();
+ private Optional<String> networkName = Optional.absent();
+ private Set<Instance.ServiceAccount> serviceAccounts = Sets.newLinkedHashSet();
+ private boolean enableNat = true;
+ private Set<PersistentDisk> disks = Sets.newLinkedHashSet();
+ private Optional<Long> bootDiskSize = Optional.absent();
+ private boolean keepBootDisk = false;
+
+ @Override
+ public GoogleComputeEngineTemplateOptions clone() {
+ GoogleComputeEngineTemplateOptions options = new GoogleComputeEngineTemplateOptions();
+ copyTo(options);
+ return options;
+ }
+
+ @Override
+ public void copyTo(TemplateOptions to) {
+ super.copyTo(to);
+ if (to instanceof GoogleComputeEngineTemplateOptions) {
+ GoogleComputeEngineTemplateOptions eTo = GoogleComputeEngineTemplateOptions.class.cast(to);
+ eTo.network(getNetwork().orNull());
+ eTo.serviceAccounts(getServiceAccounts());
+ eTo.enableNat(isEnableNat());
+ eTo.disks(getDisks());
+ eTo.keepBootDisk(shouldKeepBootDisk());
+ }
+ }
+
+ /**
+ * @deprecated See TemplateOptions#networks
+ * @see #getNetworkName()
+ */
+ @Deprecated
+ public GoogleComputeEngineTemplateOptions network(String networkName) {
+ return this.networks(networkName);
+ }
+
+ /**
+ * @see #getNetwork()
+ */
+ public GoogleComputeEngineTemplateOptions network(URI network) {
+ this.network = fromNullable(network);
+ return this;
+ }
+
+ /**
+ * @see #getServiceAccounts()
+ * @see ServiceAccount
+ */
+ public GoogleComputeEngineTemplateOptions addServiceAccount(ServiceAccount serviceAccout) {
+ this.serviceAccounts.add(serviceAccout);
+ return this;
+ }
+
+ /**
+ * @see #getServiceAccounts()
+ * @see ServiceAccount
+ */
+ public GoogleComputeEngineTemplateOptions serviceAccounts(Set<ServiceAccount> serviceAccounts) {
+ this.serviceAccounts = Sets.newLinkedHashSet(serviceAccounts);
+ return this;
+ }
+
+ /**
+ * @see #getDisks()
+ * @see org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk
+ */
+ public GoogleComputeEngineTemplateOptions addDisk(PersistentDisk disk) {
+ this.disks.add(disk);
+ return this;
+ }
+
+ /**
+ * @see #getDisks()
+ * @see org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk
+ */
+ public GoogleComputeEngineTemplateOptions disks(Set<PersistentDisk> disks) {
+ this.disks = Sets.newLinkedHashSet(disks);
+ return this;
+ }
+
+ /**
+ * @see #isEnableNat()
+ */
+ public GoogleComputeEngineTemplateOptions enableNat(boolean enableNat) {
+ this.enableNat = enableNat;
+ return this;
+ }
+
+ /**
+ * @see #getBootDiskSize()
+ */
+ public GoogleComputeEngineTemplateOptions bootDiskSize(Long bootDiskSize) {
+ this.bootDiskSize = fromNullable(bootDiskSize);
+ return this;
+ }
+
+ /**
+ * @see #shouldKeepBootDisk()
+ */
+ public GoogleComputeEngineTemplateOptions keepBootDisk(boolean keepBootDisk) {
+ this.keepBootDisk = keepBootDisk;
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions blockOnPort(int port, int seconds) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.blockOnPort(port, seconds));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions inboundPorts(int... ports) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.inboundPorts(ports));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions authorizePublicKey(String publicKey) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions installPrivateKey(String privateKey) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.installPrivateKey(privateKey));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions blockUntilRunning(boolean blockUntilRunning) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions dontAuthorizePublicKey() {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.dontAuthorizePublicKey());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions nameTask(String name) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.nameTask(name));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions runAsRoot(boolean runAsRoot) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.runAsRoot(runAsRoot));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions runScript(Statement script) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.runScript(script));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions overrideLoginCredentials(LoginCredentials overridingCredentials) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.overrideLoginCredentials(overridingCredentials));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions overrideLoginPassword(String password) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.overrideLoginPassword(password));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions overrideLoginPrivateKey(String privateKey) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.overrideLoginPrivateKey(privateKey));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions overrideLoginUser(String loginUser) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.overrideLoginUser(loginUser));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.overrideAuthenticateSudo(authenticateSudo));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions userMetadata(Map<String, String> userMetadata) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.userMetadata(userMetadata));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions userMetadata(String key, String value) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.userMetadata(key, value));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions nodeNames(Iterable<String> nodeNames) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.nodeNames(nodeNames));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions networks(Iterable<String> networks) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.networks(networks));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions networks(String... networks) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.networks(networks));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions tags(Iterable<String> tags) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.tags(tags));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions wrapInInitScript(boolean wrapInInitScript) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.wrapInInitScript(wrapInInitScript));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions runScript(String script) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.runScript(script));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GoogleComputeEngineTemplateOptions blockOnComplete(boolean blockOnComplete) {
+ return GoogleComputeEngineTemplateOptions.class.cast(super.blockOnComplete(blockOnComplete));
+ }
+
+ /**
+ * @return the ServiceAccounts to enable in the instances.
+ */
+ public Set<Instance.ServiceAccount> getServiceAccounts() {
+ return serviceAccounts;
+ }
+
+ /**
+ * @return the PersistentDisks for this instance.
+ */
+ public Set<PersistentDisk> getDisks() {
+ return disks;
+ }
+
+ /**
+ * @return the URI of an existing network the instances will be attached to. If no network URI or network name are
+ * provided a new network will be created for the project.
+ */
+ public Optional<URI> getNetwork() {
+ return network;
+ }
+
+ /**
+ * @return the name of an existing network the instances will be attached to, the network is assumed to belong to
+ * user's project. If no network URI network name are provided a new network will be created for the project.
+ * <b>Note that this is now pulling from the first element in the networks field from TemplateOptions.</b>
+ */
+ public Optional<String> getNetworkName() {
+ return fromNullable(Iterables.getFirst(getNetworks(), null));
+ }
+
+ /**
+ * @return whether an AccessConfig with Type ONE_TO_ONE_NAT should be enabled in the instances. When true
+ * instances will have a NAT address that will be publicly accessible.
+ */
+ public boolean isEnableNat() {
+ return enableNat;
+ }
+
+ /**
+ * @return the boot disk size, if specified. Defaults to 10gb.
+ */
+ public Optional<Long> getBootDiskSize() {
+ return bootDiskSize;
+ }
+
+ /**
+ * @return whether we should keep the boot disk around when deleting the instance. Defaults to false.
+ */
+ public boolean shouldKeepBootDisk() {
+ return keepBootDisk;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
new file mode 100644
index 0000000..38066ba
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/predicates/AllNodesInGroupTerminated.java
@@ -0,0 +1,48 @@
+/*
+ * 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.predicates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.all;
+import static com.google.common.collect.Sets.filter;
+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;
+
+@Singleton
+public class AllNodesInGroupTerminated implements Predicate<String> {
+
+ private final ComputeService computeService;
+
+ @Inject
+ public AllNodesInGroupTerminated(ComputeService computeService) {
+ this.computeService = checkNotNull(computeService, "compute service");
+ }
+
+
+ @Override
+ public boolean apply(String groupName) {
+ return all(filter(computeService.listNodesDetailsMatching(all()), inGroup(groupName)), TERMINATED);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
new file mode 100644
index 0000000..14af9cd
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
@@ -0,0 +1,183 @@
+/*
+ * 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.strategy;
+
+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;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
+import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
+import org.jclouds.compute.strategy.ListNodesStrategy;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.functions.FirewallTagNamingConvention;
+import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Firewall;
+import org.jclouds.googlecomputeengine.domain.Network;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.features.FirewallApi;
+import org.jclouds.googlecomputeengine.options.FirewallOptions;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.Atomics;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+
+public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
+ org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet {
+
+ public static final String EXTERIOR_RANGE = "0.0.0.0/0";
+ public static final String DEFAULT_INTERNAL_NETWORK_RANGE = "10.0.0.0/8";
+
+ private final GoogleComputeEngineApi api;
+ private final Supplier<String> userProject;
+ private final LoadingCache<NetworkAndAddressRange, Network> networkMap;
+ private final Predicate<AtomicReference<Operation>> operationDonePredicate;
+ private final long operationCompleteCheckInterval;
+ private final long operationCompleteCheckTimeout;
+ private final FirewallTagNamingConvention.Factory firewallTagNamingConvention;
+
+ @Inject
+ protected CreateNodesWithGroupEncodedIntoNameThenAddToSet(
+ CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy,
+ ListNodesStrategy listNodesStrategy,
+ GroupNamingConvention.Factory namingConvention,
+ @Named(Constants.PROPERTY_USER_THREADS)
+ ListeningExecutorService userExecutor,
+ CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory
+ customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
+ GoogleComputeEngineApi api,
+ @UserProject Supplier<String> userProject,
+ @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
+ @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
+ @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout,
+ LoadingCache<NetworkAndAddressRange, Network> networkMap,
+ FirewallTagNamingConvention.Factory firewallTagNamingConvention) {
+ super(addNodeWithGroupStrategy, listNodesStrategy, namingConvention, userExecutor,
+ customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
+
+ this.api = checkNotNull(api, "google compute api");
+ this.userProject = checkNotNull(userProject, "user project name");
+ this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
+ "operation completed check interval");
+ this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
+ "operation completed check timeout");
+ this.operationDonePredicate = checkNotNull(operationDonePredicate, "operationDonePredicate");
+ this.networkMap = checkNotNull(networkMap, "networkMap");
+ this.firewallTagNamingConvention = checkNotNull(firewallTagNamingConvention, "firewallTagNamingConvention");
+ }
+
+ @Override
+ public synchronized Map<?, ListenableFuture<Void>> execute(String group, int count,
+ Template template,
+ Set<NodeMetadata> goodNodes,
+ Map<NodeMetadata, Exception> badNodes,
+ Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
+
+ String sharedResourceName = namingConvention.create().sharedNameForGroup(group);
+ Template mutableTemplate = template.clone();
+ GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class.cast(mutableTemplate
+ .getOptions());
+ assert template.getOptions().equals(templateOptions) : "options didn't clone properly";
+
+ // get or create the network and create a firewall with the users configuration
+ Network network = getOrCreateNetwork(templateOptions, sharedResourceName);
+ getOrCreateFirewalls(templateOptions, network, firewallTagNamingConvention.get(group));
+ templateOptions.network(network.getSelfLink());
+ templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
+
+ return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
+ }
+
+ /**
+ * Try and find a network either previously created by jclouds or user defined.
+ */
+ private Network getOrCreateNetwork(GoogleComputeEngineTemplateOptions templateOptions, String sharedResourceName) {
+
+ String networkName = templateOptions.getNetworkName().or(sharedResourceName);
+
+ return networkMap.apply(new NetworkAndAddressRange(networkName, DEFAULT_INTERNAL_NETWORK_RANGE, null));
+ }
+
+ /**
+ * Ensures that a firewall exists for every inbound port that the instance requests.
+ * <p>
+ * For each port, there must be a firewall with a name following the {@link FirewallTagNamingConvention},
+ * with a target tag also following the {@link FirewallTagNamingConvention}, which opens the requested port
+ * for all sources on both TCP and UDP protocols.
+ * @see org.jclouds.googlecomputeengine.features.FirewallApi#patch(String, org.jclouds.googlecomputeengine.options.FirewallOptions)
+ */
+ private void getOrCreateFirewalls(GoogleComputeEngineTemplateOptions templateOptions, Network network,
+ FirewallTagNamingConvention naming) {
+
+ String projectName = userProject.get();
+ FirewallApi firewallApi = api.getFirewallApiForProject(projectName);
+ Set<AtomicReference<Operation>> operations = Sets.newHashSet();
+
+ for (Integer port : templateOptions.getInboundPorts()) {
+ String name = naming.name(port);
+ Firewall firewall = firewallApi.get(name);
+ if (firewall == null) {
+ ImmutableSet<Firewall.Rule> rules = ImmutableSet.of(Firewall.Rule.permitTcpRule(port), Firewall.Rule.permitUdpRule(port));
+ FirewallOptions firewallOptions = new FirewallOptions()
+ .name(name)
+ .network(network.getSelfLink())
+ .allowedRules(rules)
+ .sourceTags(templateOptions.getTags())
+ .sourceRanges(of(DEFAULT_INTERNAL_NETWORK_RANGE, EXTERIOR_RANGE))
+ .targetTags(ImmutableSet.of(name));
+ AtomicReference<Operation> operation = Atomics.newReference(firewallApi.createInNetwork(
+ firewallOptions.getName(),
+ network.getSelfLink(),
+ firewallOptions));
+ operations.add(operation);
+ }
+ }
+
+ for (AtomicReference<Operation> operation : operations) {
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
+ MILLISECONDS).apply(operation);
+ checkState(!operation.get().getHttpError().isPresent(),
+ "Could not create firewall, operation failed" + operation);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
new file mode 100644
index 0000000..082d9ed
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/PopulateDefaultLoginCredentialsForImageStrategy.java
@@ -0,0 +1,69 @@
+/*
+ * 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.strategy;
+
+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 org.jclouds.compute.domain.TemplateBuilderSpec;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ssh.internal.RsaSshKeyPairGenerator;
+
+import com.google.inject.Inject;
+
+@Singleton
+public class PopulateDefaultLoginCredentialsForImageStrategy implements
+ org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy {
+
+ private final TemplateBuilderSpec templateBuilder;
+ private final RsaSshKeyPairGenerator keyPairGenerator;
+ private String compoundKey;
+
+ @Inject
+ PopulateDefaultLoginCredentialsForImageStrategy(@Named(TEMPLATE) String templateSpec,
+ RsaSshKeyPairGenerator keyPairGenerator)
+ throws NoSuchAlgorithmException {
+ this.templateBuilder = TemplateBuilderSpec.parse(checkNotNull(templateSpec, "template builder spec"));
+ checkNotNull(templateBuilder.getLoginUser(), "template builder spec must provide a loginUser");
+ this.keyPairGenerator = checkNotNull(keyPairGenerator, "keypair generator");
+ }
+
+ @PostConstruct
+ private void generateKeys() {
+ Map<String, String> keys = keyPairGenerator.get();
+ // as we need to store both the pubk and the pk, store them separated by : (base64 does not contain that char)
+ compoundKey = String.format("%s:%s", checkNotNull(keys.get("public"), "public key cannot be null"),
+ checkNotNull(keys.get("private"), "private key cannot be null"));
+ }
+
+ @Override
+ public LoginCredentials apply(Object image) {
+ return LoginCredentials.builder()
+ .authenticateSudo(templateBuilder.getAuthenticateSudo() != null ?
+ templateBuilder.getAuthenticateSudo() : false)
+ .privateKey(compoundKey)
+ .user(templateBuilder.getLoginUser()).build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
new file mode 100644
index 0000000..ff75a03
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/UseNodeCredentialsButOverrideFromTemplate.java
@@ -0,0 +1,57 @@
+/*
+ * 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.strategy;
+
+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 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,
+ * as such only overriding the TemplateOptions credentials is required.
+ */
+@Singleton
+public class UseNodeCredentialsButOverrideFromTemplate extends PrioritizeCredentialsFromTemplate {
+
+
+ @Inject
+ public UseNodeCredentialsButOverrideFromTemplate(
+ Function<Template, LoginCredentials> credentialsFromImageOrTemplateOptions) {
+ super(credentialsFromImageOrTemplateOptions);
+ }
+
+ public LoginCredentials apply(Template template, LoginCredentials fromNode) {
+ RunScriptOptions options = checkNotNull(template.getOptions(), "template options are required");
+ LoginCredentials.Builder builder = LoginCredentials.builder(fromNode);
+ if (options.getLoginUser() != null)
+ builder.user(template.getOptions().getLoginUser());
+ if (options.getLoginPassword() != null)
+ builder.password(options.getLoginPassword());
+ if (options.getLoginPrivateKey() != null)
+ builder.privateKey(options.getLoginPrivateKey());
+ if (options.shouldAuthenticateSudo() != null && options.shouldAuthenticateSudo())
+ builder.authenticateSudo(true);
+ return builder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
new file mode 100644
index 0000000..2a1b3f2
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
@@ -0,0 +1,177 @@
+/*
+ * 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.config;
+
+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;
+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.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;
+import org.jclouds.http.annotation.Redirection;
+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;
+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;
+
+/**
+ * Configures the GoogleCompute connection.
+ */
+@ConfiguresHttpApi
+public class GoogleComputeEngineHttpApiModule extends HttpApiModule<GoogleComputeEngineApi> {
+ public GoogleComputeEngineHttpApiModule() {
+ }
+
+ @Override
+ protected void configure() {
+ bind(DateAdapter.class).to(Iso8601DateAdapter.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();
+ }
+
+ @Override
+ protected void bindErrorHandlers() {
+ bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GoogleComputeEngineErrorHandler.class);
+ bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(GoogleComputeEngineErrorHandler.class);
+ bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(GoogleComputeEngineErrorHandler.class);
+ }
+
+ @Provides
+ @Singleton
+ @UserProject
+ 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) {
+ // ID should be of the form project_id@developer.gserviceaccount.com
+ // OR (increasingly often) project_id-extended_uid@developer.gserviceaccount.com
+ // where project_id is the NUMBER;
+ // HERE we also accept simply "project" as the identity, if no "@" is present;
+ // this is used in tests, but not sure if it is valid in the wild.
+ String projectName = in.identity;
+ if (projectName.indexOf("@") != -1) {
+ projectName = Iterables.get(Splitter.on("@").split(projectName), 0);
+ if (projectName.indexOf("-") != -1) {
+ // if ID is of the form project_id-extended_uid@developer.gserviceaccount.com
+ projectName = Iterables.get(Splitter.on("-").split(projectName), 0);
+ }
+ }
+ Project project = api.getProjectApi().get(projectName);
+ return project.getName();
+ }
+ }, creds), seconds, TimeUnit.SECONDS);
+ }
+
+ @Provides
+ @Singleton
+ @Named("machineTypeToURI")
+ public Function<String, URI> provideMachineTypeNameToURIFunction(@Provider final Supplier<URI> endpoint,
+ @UserProject final Supplier<String> userProject) {
+ return new Function<String, URI>() {
+ @Override
+ public URI apply(String input) {
+ 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("networkToURI")
+ public Function<String, URI> provideNetworkNameToURIFunction(@Provider final Supplier<URI> endpoint,
+ @UserProject final Supplier<String> userProject) {
+ return new Function<String, URI>() {
+ @Override
+ public URI apply(String input) {
+ return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
+ .appendPath("/global/networks/").appendPath(input).build();
+ }
+ };
+ }
+
+ @Provides
+ @Singleton
+ @Named("zoneToURI")
+ public Function<String, URI> provideZoneNameToURIFunction(@Provider final Supplier<URI> endpoint,
+ @UserProject final Supplier<String> userProject) {
+ return new Function<String, URI>() {
+ @Override
+ public URI apply(String input) {
+ return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
+ .appendPath("/zones/").appendPath(input).build();
+ }
+ };
+ }
+
+ @Provides
+ @Singleton
+ @Named("regionToURI")
+ public Function<String, URI> provideRegionNameToURIFunction(@Provider final Supplier<URI> endpoint,
+ @UserProject final Supplier<String> userProject) {
+ return new Function<String, URI>() {
+ @Override
+ public URI apply(String input) {
+ return Uris.uriBuilder(endpoint.get()).appendPath("/projects/").appendPath(userProject.get())
+ .appendPath("/regions/").appendPath(input).build();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
new file mode 100644
index 0000000..cd7e8d1
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
@@ -0,0 +1,413 @@
+/*
+ * 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.config;
+
+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.domain.Quota;
+import org.jclouds.googlecomputeengine.options.FirewallOptions;
+import org.jclouds.googlecomputeengine.options.RouteOptions;
+import org.jclouds.json.config.GsonModule;
+import org.jclouds.net.domain.IpProtocol;
+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;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+
+public class GoogleComputeEngineParserModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
+ }
+
+ @Provides
+ @Singleton
+ public Map<Type, Object> provideCustomAdapterBindings() {
+ return new ImmutableMap.Builder<Type, Object>()
+ .put(Metadata.class, new MetadataTypeAdapter())
+ .put(Operation.class, new OperationTypeAdapter())
+ .put(Header.class, new HeaderTypeAdapter())
+ .put(ClaimSet.class, new ClaimSetTypeAdapter())
+ .put(Project.class, new ProjectTypeAdapter())
+ .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();
+ }
+
+ /**
+ * Parser for operations that unwraps errors avoiding an extra intermediate object.
+ *
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1/operations"/>
+ */
+ @Singleton
+ private static class OperationTypeAdapter implements JsonDeserializer<Operation> {
+
+ @Override
+ public Operation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
+ JsonParseException {
+ Operation.Builder operationBuilder = ((Operation) context.deserialize(json,
+ OperationInternal.class)).toBuilder();
+ JsonObject error = json.getAsJsonObject().getAsJsonObject("error");
+ if (error != null) {
+ JsonArray array = error.getAsJsonArray("errors");
+ if (array != null) {
+ for (JsonElement element : array) {
+ operationBuilder.addError((Operation.Error) context.deserialize(element, Operation.Error.class));
+ }
+ }
+ }
+ return operationBuilder.build();
+ }
+
+ private static class OperationInternal extends Operation {
+ @ConstructorProperties({
+ "id", "creationTimestamp", "selfLink", "name", "description", "targetLink", "targetId",
+ "clientOperationId", "status", "statusMessage", "user", "progress", "insertTime", "startTime",
+ "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, URI region, URI zone) {
+ super(id, creationTimestamp, selfLink, name, description, targetLink, targetId, clientOperationId,
+ status, statusMessage, user, progress, insertTime, startTime, endTime, httpErrorStatusCode,
+ httpErrorMessage, operationType, null, region, zone);
+ }
+ }
+ }
+
+ @Singleton
+ private static class InstanceTemplateTypeAdapter implements JsonSerializer<InstanceTemplate> {
+
+ @Override
+ public JsonElement serialize(InstanceTemplate src, Type typeOfSrc, JsonSerializationContext context) {
+ InstanceTemplateInternal template = new InstanceTemplateInternal(src);
+ JsonObject instance = (JsonObject) context.serialize(template, InstanceTemplateInternal.class);
+
+ // deal with network
+ JsonArray networkInterfaces = new JsonArray();
+ for (InstanceTemplate.NetworkInterface networkInterface : template.getNetworkInterfaces()){
+ networkInterfaces.add(context.serialize(networkInterface, InstanceTemplate.NetworkInterface.class));
+ }
+ instance.add("networkInterfaces", networkInterfaces);
+
+ // deal with persistent disks
+ if (src.getDisks() != null && !src.getDisks().isEmpty()) {
+ JsonArray disks = new JsonArray();
+ for (InstanceTemplate.PersistentDisk persistentDisk : src.getDisks()) {
+ JsonObject disk = (JsonObject) context.serialize(persistentDisk, InstanceTemplate.PersistentDisk.class);
+ disk.addProperty("type", "PERSISTENT");
+ disks.add(disk);
+ }
+ instance.add("disks", disks);
+ }
+
+ // deal with metadata
+ if (src.getMetadata() != null && !src.getMetadata().isEmpty()) {
+ Metadata metadata = Metadata.builder()
+ .items(src.getMetadata())
+ .build();
+ JsonObject metadataJson = (JsonObject) context.serialize(metadata);
+ instance.add("metadata", metadataJson);
+ return instance;
+ }
+
+ return instance;
+ }
+
+ private static class InstanceTemplateInternal extends InstanceTemplate {
+ private InstanceTemplateInternal(InstanceTemplate template) {
+ super(template.getMachineType());
+ name(template.getName());
+ description(template.getDescription());
+ image(template.getImage());
+ serviceAccounts(template.getServiceAccounts());
+ networkInterfaces(template.getNetworkInterfaces());
+ }
+ }
+ }
+
+ @Singleton
+ private static class InstanceTypeAdapter implements JsonDeserializer<Instance> {
+
+ @Override
+ public Instance deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
+ JsonParseException {
+ Instance.Builder instanceBuilder = ((Instance) context.deserialize(json,
+ InstanceInternal.class)).toBuilder();
+ JsonObject object = (JsonObject) json;
+ if (object.get("disks") != null) {
+ JsonArray disks = (JsonArray) object.get("disks");
+ for (JsonElement element : disks) {
+ JsonObject disk = (JsonObject) element;
+ if (disk.get("type").getAsString().equals("PERSISTENT")) {
+ instanceBuilder.addDisk((Instance.PersistentAttachedDisk) context.deserialize(disk,
+ Instance.PersistentAttachedDisk.class));
+ } else {
+ instanceBuilder.addDisk((Instance.AttachedDisk) context.deserialize(disk,
+ Instance.AttachedDisk.class));
+ }
+ }
+
+ }
+
+ return Instance.builder().fromInstance(instanceBuilder.build()).build();
+ }
+
+
+ private static class InstanceInternal extends Instance {
+ @ConstructorProperties({
+ "id", "creationTimestamp", "selfLink", "name", "description", "tags", "machineType",
+ "status", "statusMessage", "zone", "networkInterfaces", "metadata", "serviceAccounts"
+ })
+ private InstanceInternal(String id, Date creationTimestamp, URI selfLink, String name, String description,
+ Tags tags, URI machineType, Status status, String statusMessage,
+ URI zone, Set<NetworkInterface> networkInterfaces, Metadata metadata,
+ Set<ServiceAccount> serviceAccounts) {
+ super(id, creationTimestamp, selfLink, name, description, tags, machineType,
+ status, statusMessage, zone, networkInterfaces, null, metadata, serviceAccounts);
+ }
+ }
+ }
+
+ /**
+ * Parser for Metadata.
+ */
+ @Singleton
+ private static class MetadataTypeAdapter implements JsonDeserializer<Metadata>, JsonSerializer<Metadata> {
+
+
+ @Override
+ public Metadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
+ JsonParseException {
+ ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+ JsonObject metadata = json.getAsJsonObject();
+ JsonArray items = metadata.getAsJsonArray("items");
+ if (items != null) {
+ for (JsonElement element : items) {
+ JsonObject object = element.getAsJsonObject();
+ builder.put(object.get("key").getAsString(), object.get("value").getAsString());
+ }
+ }
+ String fingerprint = null;
+ if (metadata.getAsJsonPrimitive("fingerprint") != null) {
+ fingerprint = metadata.getAsJsonPrimitive("fingerprint").getAsString();
+ } else {
+ fingerprint = "";
+ }
+ return new Metadata(fingerprint, builder.build());
+ }
+
+ @Override
+ public JsonElement serialize(Metadata src, Type typeOfSrc, JsonSerializationContext context) {
+ JsonObject metadataObject = new JsonObject();
+ metadataObject.add("kind", new JsonPrimitive("compute#metadata"));
+ JsonArray items = new JsonArray();
+ 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;
+ }
+ }
+
+
+
+ @Singleton
+ private static class ProjectTypeAdapter implements JsonDeserializer<Project> {
+
+ @Override
+ public Project deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
+ JsonParseException {
+ return Project.builder().fromProject((Project) context.deserialize(json, ProjectInternal.class)).build();
+ }
+
+ private static class ProjectInternal extends Project {
+
+ @ConstructorProperties({
+ "id", "creationTimestamp", "selfLink", "name", "description", "commonInstanceMetadata", "quotas",
+ "externalIpAddresses"
+ })
+ private ProjectInternal(String id, Date creationTimestamp, URI selfLink, String name, String description,
+ Metadata commonInstanceMetadata, Set<Quota> quotas, Set<String> externalIpAddresses) {
+ super(id, creationTimestamp, selfLink, name, description, commonInstanceMetadata, quotas,
+ externalIpAddresses);
+ }
+
+ }
+ }
+
+ @Singleton
+ private static class FirewallOptionsTypeAdapter implements JsonSerializer<FirewallOptions> {
+
+ @Override
+ public JsonElement serialize(FirewallOptions src, Type typeOfSrc, JsonSerializationContext context) {
+ JsonObject firewall = new JsonObject();
+ if (src.getName() != null) {
+ firewall.addProperty("name", src.getName());
+ }
+ if (src.getNetwork() != null) {
+ firewall.addProperty("network", src.getNetwork().toString());
+ }
+ if (!src.getSourceRanges().isEmpty()) {
+ firewall.add("sourceRanges", buildArrayOfStrings(src.getSourceRanges()));
+ }
+ if (!src.getSourceTags().isEmpty()) {
+ firewall.add("sourceTags", buildArrayOfStrings(src.getSourceTags()));
+ }
+ if (!src.getTargetTags().isEmpty()) {
+ firewall.add("targetTags", buildArrayOfStrings(src.getTargetTags()));
+ }
+ if (!src.getAllowed().isEmpty()) {
+ JsonArray rules = new JsonArray();
+ for (Rule rule : src.getAllowed()) {
+ rules.add(context.serialize(rule, Firewall.Rule.class));
+ }
+ firewall.add("allowed", rules);
+ }
+ return firewall;
+ }
+ }
+
+ @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) {
+ array.add(new JsonPrimitive(string));
+ }
+ return array;
+ }
+
+
+ private static class RuleTypeAdapter implements JsonDeserializer<Firewall.Rule>, JsonSerializer<Firewall.Rule> {
+
+ @Override
+ public Firewall.Rule deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
+ JsonParseException {
+ JsonObject rule = json.getAsJsonObject();
+ Rule.Builder builder = Rule.builder();
+ builder.IpProtocol(IpProtocol.fromValue(rule.get("IPProtocol").getAsString()));
+ if (rule.get("ports") != null) {
+ JsonArray ports = (JsonArray) rule.get("ports");
+ for (JsonElement port : ports) {
+ String portAsString = port.getAsString();
+ if (portAsString.contains("-")) {
+ String[] split = portAsString.split("-");
+ builder.addPortRange(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+ } else {
+ builder.addPort(Integer.parseInt(portAsString));
+ }
+ }
+ }
+ return builder.build();
+ }
+
+ @Override
+ public JsonElement serialize(Firewall.Rule src, Type typeOfSrc, JsonSerializationContext context) {
+ JsonObject ruleObject = new JsonObject();
+ ruleObject.addProperty("IPProtocol", src.getIpProtocol().value());
+ if (src.getPorts() != null && !src.getPorts().isEmpty()) {
+ JsonArray ports = new JsonArray();
+ for (Range<Integer> range : src.getPorts().asRanges()) {
+ ports.add(new JsonPrimitive(range.lowerEndpoint() == range.upperEndpoint() ? range.lowerEndpoint() + "" :
+ range.lowerEndpoint() + "-" + range.upperEndpoint()));
+ }
+ ruleObject.add("ports", ports);
+ }
+ return ruleObject;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
new file mode 100644
index 0000000..157dd9b
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/OAuthModuleWithoutTypeAdapters.java
@@ -0,0 +1,51 @@
+/*
+ * 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.config;
+
+import org.jclouds.oauth.v2.config.OAuthModule;
+import org.jclouds.oauth.v2.domain.OAuthCredentials;
+import org.jclouds.oauth.v2.domain.Token;
+import org.jclouds.oauth.v2.domain.TokenRequest;
+import org.jclouds.oauth.v2.functions.BuildTokenRequest;
+import org.jclouds.oauth.v2.functions.FetchToken;
+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/>
+ * TODO overcome this by using multibindings on GSonModule?
+ */
+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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
new file mode 100644
index 0000000..e932d1c
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/config/UserProject.java
@@ -0,0 +1,33 @@
+/*
+ * 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.config;
+
+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.
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
+@Qualifier
+public @interface UserProject {
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
new file mode 100644
index 0000000..2cc8d8e
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
@@ -0,0 +1,121 @@
+/*
+ * 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
+ *
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1/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/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
new file mode 100644
index 0000000..207cf75
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
@@ -0,0 +1,177 @@
+/*
+ * 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.
+ *
+ * @see <a href="https://developers.google.com/compute/docs/reference/v1/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());
+ }
+ }
+
+}