Deprecate user metadata in DigitalOcean

This commit is contained in:
Ignasi Barrera 2016-12-07 17:16:51 +01:00
parent 92044e3d44
commit baab388c57
2 changed files with 35 additions and 11 deletions

View File

@ -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 static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; 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.Size;
import org.jclouds.digitalocean2.domain.options.CreateDropletOptions; import org.jclouds.digitalocean2.domain.options.CreateDropletOptions;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.json.Json;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -68,18 +66,15 @@ public class DigitalOcean2ComputeServiceAdapter implements ComputeServiceAdapter
private final Predicate<Integer> nodeRunningPredicate; private final Predicate<Integer> nodeRunningPredicate;
private final Predicate<Integer> nodeStoppedPredicate; private final Predicate<Integer> nodeStoppedPredicate;
private final Predicate<Integer> nodeTerminatedPredicate; private final Predicate<Integer> nodeTerminatedPredicate;
private final Json json;
@Inject DigitalOcean2ComputeServiceAdapter(DigitalOcean2Api api, @Inject DigitalOcean2ComputeServiceAdapter(DigitalOcean2Api api,
@Named(TIMEOUT_NODE_RUNNING) Predicate<Integer> nodeRunningPredicate, @Named(TIMEOUT_NODE_RUNNING) Predicate<Integer> nodeRunningPredicate,
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<Integer> nodeStoppedPredicate, @Named(TIMEOUT_NODE_SUSPENDED) Predicate<Integer> nodeStoppedPredicate,
@Named(TIMEOUT_NODE_TERMINATED) Predicate<Integer> nodeTerminatedPredicate, @Named(TIMEOUT_NODE_TERMINATED) Predicate<Integer> nodeTerminatedPredicate) {
Json json) {
this.api = api; this.api = api;
this.nodeRunningPredicate = nodeRunningPredicate; this.nodeRunningPredicate = nodeRunningPredicate;
this.nodeStoppedPredicate = nodeStoppedPredicate; this.nodeStoppedPredicate = nodeStoppedPredicate;
this.nodeTerminatedPredicate = nodeTerminatedPredicate; this.nodeTerminatedPredicate = nodeTerminatedPredicate;
this.json = json;
} }
private void setUserDataIfSupported(Template template, CreateDropletOptions.Builder options, String userData) { 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. // Encoding tags or anything else than user_data in here breaks their functionality.
if (null != templateOptions.getUserData()) { if (null != templateOptions.getUserData()) {
setUserDataIfSupported(template, options, new String(templateOptions.getUserData())); setUserDataIfSupported(template, options, new String(templateOptions.getUserData()));
} } else if (null != templateOptions.getUserMetadata().get("user_data")) {
// Backwards compatible variant, getting userData from userMetaData map. // Backwards compatible variant, getting userData from userMetaData map.
Map<String, String> metadataAndTags = templateOptions.getUserMetadata(); setUserDataIfSupported(template, options, templateOptions.getUserMetadata().get("user_data"));
if (null != metadataAndTags.get("user_data")) {
setUserDataIfSupported(template, options, metadataAndTags.get("user_data"));
} }
DropletCreate dropletCreated = api.dropletApi().create(name, DropletCreate dropletCreated = api.dropletApi().create(name,

View File

@ -20,6 +20,7 @@ import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -78,6 +79,36 @@ public class DigitalOcean2TemplateOptions extends TemplateOptions implements Clo
return this; return this;
} }
/**
* @deprecated Key value metadata is not supported in DigitalOcean. Use
* {@link #userData(byte[])} instead.
*/
@Deprecated
@Override
public TemplateOptions userMetadata(Map<String, String> 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<String, String> getUserMetadata() {
return super.getUserMetadata();
}
public Set<Integer> getSshKeyIds() { public Set<Integer> getSshKeyIds() {
return sshKeyIds; return sshKeyIds;
} }