mirror of https://github.com/apache/jclouds.git
Incorporate code review comments from @jclouds
This commit is contained in:
parent
e232aed0ca
commit
ddb70df2d9
|
@ -24,7 +24,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Task;
|
|||
/**
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
public class VCloudDirectorException extends VCloudDirectorRuntimeException {
|
||||
public class VCloudDirectorException extends RuntimeException {
|
||||
|
||||
/** The serialVersionUID. */
|
||||
private static final long serialVersionUID = -5292516858598372960L;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.vcloud.director.v1_5;
|
||||
|
||||
/**
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
public class VCloudDirectorRuntimeException extends RuntimeException {
|
||||
|
||||
/** The serialVersionUID. */
|
||||
private static final long serialVersionUID = -8590262859549695447L;
|
||||
|
||||
public VCloudDirectorRuntimeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -18,16 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.*;
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorRuntimeException;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -46,6 +47,9 @@ import com.google.common.collect.Iterables;
|
|||
@XmlRootElement(name = "Error")
|
||||
public class Error {
|
||||
|
||||
@Resource
|
||||
protected static Logger logger = Logger.NULL;
|
||||
|
||||
public static enum Code {
|
||||
|
||||
OK(200),
|
||||
|
@ -60,10 +64,11 @@ public class Error {
|
|||
NOT_ALLOWED(405),
|
||||
INTERNAL_ERROR(500),
|
||||
NOT_IMPLEMENTED(501),
|
||||
UNAVAILABLE(503);
|
||||
UNAVAILABLE(503),
|
||||
UNRECOGNIZED(-1);
|
||||
|
||||
private Integer majorErrorCode;
|
||||
|
||||
|
||||
private Code(Integer majorErrorCode) {
|
||||
this.majorErrorCode = majorErrorCode;
|
||||
}
|
||||
|
@ -82,7 +87,8 @@ public class Error {
|
|||
if (found.isPresent()) {
|
||||
return found.get();
|
||||
} else {
|
||||
throw new VCloudDirectorRuntimeException(String.format("Illegal major error code '%d'", majorErrorCode));
|
||||
logger.warn("Unrecognized major error code '%d'", majorErrorCode);
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,16 +23,15 @@ import static com.google.common.base.Objects.equal;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ForwardingList;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -60,7 +59,9 @@ import com.google.common.collect.Lists;
|
|||
@XmlType(name = "FilesList", propOrder = {
|
||||
"files"
|
||||
})
|
||||
public class FilesList extends ForwardingList<File> {
|
||||
public class FilesList extends ForwardingSet<File> {
|
||||
|
||||
// TODO Investigate using the same wrapper (e.g. see Tasks); can we eliminate this class?
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
|
@ -72,13 +73,13 @@ public class FilesList extends ForwardingList<File> {
|
|||
|
||||
public static class Builder {
|
||||
|
||||
private List<File> files = Lists.newLinkedList();
|
||||
private Set<File> files = Sets.newLinkedHashSet();
|
||||
|
||||
/**
|
||||
* @see FilesList#getFiles()
|
||||
*/
|
||||
public Builder files(List<File> files) {
|
||||
this.files = Lists.newLinkedList(checkNotNull(files, "files"));
|
||||
public Builder files(Iterable<File> files) {
|
||||
this.files = Sets.newLinkedHashSet(checkNotNull(files, "files"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -100,23 +101,22 @@ public class FilesList extends ForwardingList<File> {
|
|||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "File", required = true)
|
||||
private Set<File> files = Sets.newLinkedHashSet();
|
||||
|
||||
private FilesList() {
|
||||
// for JAXB
|
||||
}
|
||||
|
||||
private FilesList(List<File> files) {
|
||||
this.files = ImmutableList.copyOf(files);
|
||||
private FilesList(Iterable<File> files) {
|
||||
this.files = ImmutableSet.copyOf(files);
|
||||
}
|
||||
|
||||
|
||||
@XmlElement(name = "File", required = true)
|
||||
protected List<File> files = Lists.newLinkedList();
|
||||
|
||||
/**
|
||||
* Gets the value of the file property.
|
||||
*/
|
||||
public List<File> getFiles() {
|
||||
return Collections.unmodifiableList(this.files);
|
||||
public Set<File> getFiles() {
|
||||
return Collections.unmodifiableSet(this.files);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +141,7 @@ public class FilesList extends ForwardingList<File> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<File> delegate() {
|
||||
protected Set<File> delegate() {
|
||||
return getFiles();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.*;
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* Represents vApp instantiation parameters.
|
||||
|
@ -205,6 +205,7 @@ public class InstantiateVAppParamsType<T extends InstantiateVAppParamsType<T>> e
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Builder<T> fromVAppCreationParamsType(VAppCreationParamsType<T> in) {
|
||||
return Builder.class.cast(super.fromVAppCreationParamsType(in));
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
package org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -69,15 +70,31 @@ import com.google.common.base.Objects;
|
|||
})
|
||||
public class NetworkConnection {
|
||||
|
||||
public static class IpAddressAllocationMode {
|
||||
public static final String POOL = "pool";
|
||||
public static final String DHCP = "dhcp";
|
||||
public static final String MANUAL = "manual";
|
||||
public static final String NONE = "none";
|
||||
|
||||
public static final List<String> ALL = Arrays.asList(
|
||||
POOL, DHCP, MANUAL, NONE
|
||||
);
|
||||
public static enum IpAddressAllocationMode {
|
||||
POOL("pool"),
|
||||
DHCP("dhcp"),
|
||||
MANUAL("manual"),
|
||||
NONE("none"),
|
||||
UNRECOGNIZED("unrecognized");
|
||||
|
||||
public static final List<IpAddressAllocationMode> ALL = ImmutableList.of(POOL, DHCP, MANUAL, NONE);
|
||||
|
||||
private final String label;
|
||||
private IpAddressAllocationMode(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public static IpAddressAllocationMode fromValue(String value) {
|
||||
try {
|
||||
return valueOf(checkNotNull(value, "value").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.*;
|
||||
import static com.google.common.base.Objects.equal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -27,6 +27,8 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
|
@ -44,6 +46,9 @@ import com.google.common.base.Objects.ToStringHelper;
|
|||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ReferenceType<T extends ReferenceType<T>> {
|
||||
|
||||
@javax.annotation.Resource
|
||||
protected static Logger logger = Logger.NULL;
|
||||
|
||||
public static <T extends ReferenceType<T>> Builder<T> builder() {
|
||||
return new Builder<T>();
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.jclouds.vcloud.director.v1_5.domain;
|
||||
|
||||
import static com.google.common.base.Objects.*;
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
@ -30,8 +30,6 @@ import javax.xml.bind.annotation.XmlAttribute;
|
|||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorRuntimeException;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -71,7 +69,10 @@ public abstract class ResourceEntityType<T extends ResourceEntityType<T>> extend
|
|||
UPLOAD_COPYING(12, "Upload initiated, copying contents.", true, false, false),
|
||||
UPLOAD_DISK_PENDING(13, "Upload initiated , disk contents pending.", true, false, false),
|
||||
UPLOAD_QUARANTINED(14, "Upload has been quarantined.", true, false, false),
|
||||
UPLOAD_QUARANTINE_EXPIRED(15, "Upload quarantine period has expired.", true, false, false);
|
||||
UPLOAD_QUARANTINE_EXPIRED(15, "Upload quarantine period has expired.", true, false, false),
|
||||
|
||||
// Convention is "UNRECOGNIZED", but that is already a valid state name! so using UNRECOGNIZED_VALUE
|
||||
UNRECOGNIZED_VALUE(404, "Unrecognized", false, false, false);
|
||||
|
||||
private Integer value;
|
||||
private String description;
|
||||
|
@ -117,7 +118,8 @@ public abstract class ResourceEntityType<T extends ResourceEntityType<T>> extend
|
|||
if (found.isPresent()) {
|
||||
return found.get();
|
||||
} else {
|
||||
throw new VCloudDirectorRuntimeException(String.format("Illegal status value '%d'", value));
|
||||
logger.warn("Illegal status value '%d'", value);
|
||||
return UNRECOGNIZED_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
@ -51,6 +52,9 @@ import com.google.common.collect.Sets;
|
|||
*/
|
||||
@XmlType(name = "ResourceType")
|
||||
public class ResourceType<T extends ResourceType<T>> {
|
||||
|
||||
@javax.annotation.Resource
|
||||
protected static Logger logger = Logger.NULL;
|
||||
|
||||
public NewBuilder<?> toNewBuilder() {
|
||||
throw new UnsupportedOperationException("New builder not yet implemented for this class");
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.UUID;
|
|||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.CustomOrgLdapSettings.AuthenticationMechanism;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.CustomOrgLdapSettings.ConnectorType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.NetworkConnection.IpAddressAllocationMode;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.OrgLdapSettings.LdapMode;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.cim.ResourceAllocationSettingData;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.cim.VirtualSystemSettingData;
|
||||
|
@ -1052,7 +1053,8 @@ public class Checks {
|
|||
// Check required fields
|
||||
assertNotNull(val.getNetwork(), String.format(NOT_NULL_OBJECT_FMT, "Network", "NetworkConnection"));
|
||||
assertNotNull(val.getIpAddressAllocationMode(), String.format(NOT_NULL_OBJECT_FMT, "IpAddressAllocationMode", "NetworkConnection"));
|
||||
assertTrue(NetworkConnection.IpAddressAllocationMode.ALL.contains(val.getIpAddressAllocationMode()),
|
||||
IpAddressAllocationMode mode = NetworkConnection.IpAddressAllocationMode.valueOf(val.getIpAddressAllocationMode());
|
||||
assertTrue(NetworkConnection.IpAddressAllocationMode.ALL.contains(mode),
|
||||
String.format(REQUIRED_VALUE_OBJECT_FMT, "IpAddressAllocationMode", "NetworkConnection", val.getIpAddressAllocationMode(), Iterables.toString(NetworkConnection.IpAddressAllocationMode.ALL)));
|
||||
|
||||
// Check optional fields
|
||||
|
|
Loading…
Reference in New Issue