From baab388c577ac8a23a3c2b347fdceafd8d51a74b Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Wed, 7 Dec 2016 17:16:51 +0100 Subject: [PATCH] Deprecate user metadata in DigitalOcean --- .../DigitalOcean2ComputeServiceAdapter.java | 15 +++------ .../options/DigitalOcean2TemplateOptions.java | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java index 17825513b3..b8f34ae750 100644 --- a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java +++ b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java @@ -28,7 +28,6 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_S import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED; import java.util.List; -import java.util.Map; import java.util.Set; import javax.annotation.Resource; @@ -48,7 +47,6 @@ import org.jclouds.digitalocean2.domain.Region; import org.jclouds.digitalocean2.domain.Size; import org.jclouds.digitalocean2.domain.options.CreateDropletOptions; import org.jclouds.domain.LoginCredentials; -import org.jclouds.json.Json; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -68,18 +66,15 @@ public class DigitalOcean2ComputeServiceAdapter implements ComputeServiceAdapter private final Predicate nodeRunningPredicate; private final Predicate nodeStoppedPredicate; private final Predicate nodeTerminatedPredicate; - private final Json json; @Inject DigitalOcean2ComputeServiceAdapter(DigitalOcean2Api api, @Named(TIMEOUT_NODE_RUNNING) Predicate nodeRunningPredicate, @Named(TIMEOUT_NODE_SUSPENDED) Predicate nodeStoppedPredicate, - @Named(TIMEOUT_NODE_TERMINATED) Predicate nodeTerminatedPredicate, - Json json) { + @Named(TIMEOUT_NODE_TERMINATED) Predicate nodeTerminatedPredicate) { this.api = api; this.nodeRunningPredicate = nodeRunningPredicate; this.nodeStoppedPredicate = nodeStoppedPredicate; this.nodeTerminatedPredicate = nodeTerminatedPredicate; - this.json = json; } private void setUserDataIfSupported(Template template, CreateDropletOptions.Builder options, String userData) { @@ -110,11 +105,9 @@ public class DigitalOcean2ComputeServiceAdapter implements ComputeServiceAdapter // Encoding tags or anything else than user_data in here breaks their functionality. if (null != templateOptions.getUserData()) { setUserDataIfSupported(template, options, new String(templateOptions.getUserData())); - } - // Backwards compatible variant, getting userData from userMetaData map. - Map metadataAndTags = templateOptions.getUserMetadata(); - if (null != metadataAndTags.get("user_data")) { - setUserDataIfSupported(template, options, metadataAndTags.get("user_data")); + } else if (null != templateOptions.getUserMetadata().get("user_data")) { + // Backwards compatible variant, getting userData from userMetaData map. + setUserDataIfSupported(template, options, templateOptions.getUserMetadata().get("user_data")); } DropletCreate dropletCreated = api.dropletApi().create(name, diff --git a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java index bc18a590d8..2a86f855e3 100644 --- a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java +++ b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java @@ -20,6 +20,7 @@ import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Arrays; +import java.util.Map; import java.util.Set; import org.jclouds.compute.options.TemplateOptions; @@ -77,6 +78,36 @@ public class DigitalOcean2TemplateOptions extends TemplateOptions implements Clo this.userData = userData; return this; } + + /** + * @deprecated Key value metadata is not supported in DigitalOcean. Use + * {@link #userData(byte[])} instead. + */ + @Deprecated + @Override + public TemplateOptions userMetadata(Map userMetadata) { + return super.userMetadata(userMetadata); + } + + /** + * @deprecated Key value metadata is not supported in DigitalOcean. Use + * {@link #userData(byte[])} instead. + */ + @Deprecated + @Override + public TemplateOptions userMetadata(String key, String value) { + return super.userMetadata(key, value); + } + + /** + * @deprecated Key value metadata is not supported in DigitalOcean. User data + * can be retrieved with {@link #getUserData()}. + */ + @Deprecated + @Override + public Map getUserMetadata() { + return super.getUserMetadata(); + } public Set getSshKeyIds() { return sshKeyIds;