mirror of
https://github.com/google/nomulus.git
synced 2025-05-30 09:20:29 +02:00
mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package rename. The repository is now in a broken state because the code itself hasn't been updated. However this should ensure that git correctly preserves history for each file.
This commit is contained in:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
143
java/google/registry/model/host/HostCommand.java
Normal file
143
java/google/registry/model/host/HostCommand.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed 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 com.google.domain.registry.model.host;
|
||||
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullSafeImmutableCopy;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.model.eppinput.ResourceCommand.AbstractSingleResourceCommand;
|
||||
import com.google.domain.registry.model.eppinput.ResourceCommand.ResourceCheck;
|
||||
import com.google.domain.registry.model.eppinput.ResourceCommand.ResourceCreateOrChange;
|
||||
import com.google.domain.registry.model.eppinput.ResourceCommand.ResourceUpdate;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
/** A collection of {@link HostResource} commands. */
|
||||
public class HostCommand {
|
||||
|
||||
/** The fields on "chgType" from {@link "http://tools.ietf.org/html/rfc5732"}. */
|
||||
@XmlTransient
|
||||
abstract static class HostCreateOrChange extends AbstractSingleResourceCommand
|
||||
implements ResourceCreateOrChange<HostResource.Builder> {
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@XmlElement(name = "addr")
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullSafeImmutableCopy(inetAddresses);
|
||||
}
|
||||
|
||||
public String getFullyQualifiedHostName() {
|
||||
return getTargetId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(HostResource.Builder builder) {
|
||||
if (getFullyQualifiedHostName() != null) {
|
||||
builder.setFullyQualifiedHostName(getFullyQualifiedHostName());
|
||||
}
|
||||
if (getInetAddresses() != null) {
|
||||
builder.setInetAddresses(getInetAddresses());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A create command for a {@link HostResource}, mapping "createType" from
|
||||
* {@link "http://tools.ietf.org/html/rfc5732"}.
|
||||
*/
|
||||
@XmlType(propOrder = {"targetId", "inetAddresses" })
|
||||
@XmlRootElement
|
||||
public static class Create
|
||||
extends HostCreateOrChange implements ResourceCreateOrChange<HostResource.Builder> {}
|
||||
|
||||
/** A delete command for a {@link HostResource}. */
|
||||
@XmlRootElement
|
||||
public static class Delete extends AbstractSingleResourceCommand {}
|
||||
|
||||
/** An info request for a {@link HostResource}. */
|
||||
@XmlRootElement
|
||||
public static class Info extends AbstractSingleResourceCommand {}
|
||||
|
||||
/** A check request for {@link HostResource}. */
|
||||
@XmlRootElement
|
||||
public static class Check extends ResourceCheck {}
|
||||
|
||||
/** An update to a {@link HostResource}. */
|
||||
@XmlRootElement
|
||||
@XmlType(propOrder = {"targetId", "innerAdd", "innerRemove", "innerChange"})
|
||||
public static class Update extends ResourceUpdate
|
||||
<Update.AddRemove, HostResource.Builder, Update.Change> {
|
||||
|
||||
@XmlElement(name = "chg")
|
||||
protected Change innerChange;
|
||||
|
||||
@XmlElement(name = "add")
|
||||
protected AddRemove innerAdd;
|
||||
|
||||
@XmlElement(name = "rem")
|
||||
protected AddRemove innerRemove;
|
||||
|
||||
@Override
|
||||
protected Change getNullableInnerChange() {
|
||||
return innerChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AddRemove getNullableInnerAdd() {
|
||||
return innerAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AddRemove getNullableInnerRemove() {
|
||||
return innerRemove;
|
||||
}
|
||||
|
||||
/** The add/remove type on a host update command. */
|
||||
@XmlType(propOrder = { "inetAddresses", "statusValues" })
|
||||
public static class AddRemove extends ResourceUpdate.AddRemove {
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@XmlElement(name = "addr")
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullToEmptyImmutableCopy(inetAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
/** The inner change type on a host update command. */
|
||||
@XmlType(propOrder = {"targetId", "inetAddresses" })
|
||||
public static class Change extends HostCreateOrChange {}
|
||||
|
||||
@Override
|
||||
public void applyTo(HostResource.Builder builder) throws AddRemoveSameValueException {
|
||||
super.applyTo(builder);
|
||||
if (!intersection(getInnerAdd().getInetAddresses(), getInnerRemove().getInetAddresses())
|
||||
.isEmpty()) {
|
||||
throw new AddRemoveSameValueException();
|
||||
}
|
||||
builder.addInetAddresses(getInnerAdd().getInetAddresses());
|
||||
builder.removeInetAddresses(getInnerRemove().getInetAddresses());
|
||||
}
|
||||
}
|
||||
}
|
209
java/google/registry/model/host/HostResource.java
Normal file
209
java/google/registry/model/host/HostResource.java
Normal file
|
@ -0,0 +1,209 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed 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 com.google.domain.registry.model.host;
|
||||
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static com.google.domain.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
|
||||
import static com.google.domain.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.model.EppResource;
|
||||
import com.google.domain.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
import com.google.domain.registry.model.annotations.ExternalMessagingName;
|
||||
import com.google.domain.registry.model.domain.DomainResource;
|
||||
import com.google.domain.registry.model.eppcommon.StatusValue;
|
||||
import com.google.domain.registry.model.transfer.TransferData;
|
||||
import com.google.domain.registry.model.transfer.TransferStatus;
|
||||
|
||||
import com.googlecode.objectify.Ref;
|
||||
import com.googlecode.objectify.annotation.Cache;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.IgnoreSave;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.condition.IfNull;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
/**
|
||||
* A persistable Host resource including mutable and non-mutable fields.
|
||||
*
|
||||
* <p>A host's {@link TransferData} is stored on the superordinate domain. Non-subordinate hosts
|
||||
* don't carry a full set of TransferData; all they have is lastTransferTime.
|
||||
*/
|
||||
@XmlRootElement(name = "infData")
|
||||
@XmlType(propOrder = {
|
||||
"fullyQualifiedHostName",
|
||||
"repoId",
|
||||
"status",
|
||||
"inetAddresses",
|
||||
"currentSponsorClientId",
|
||||
"creationClientId",
|
||||
"creationTime",
|
||||
"lastEppUpdateClientId",
|
||||
"lastEppUpdateTime",
|
||||
"lastTransferTime" })
|
||||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
@Entity
|
||||
@ExternalMessagingName("host")
|
||||
public class HostResource extends EppResource implements ForeignKeyedEppResource {
|
||||
|
||||
/**
|
||||
* Fully qualified hostname, which is a unique identifier for this host.
|
||||
* <p>
|
||||
* This is only unique in the sense that for any given lifetime specified as the time range from
|
||||
* (creationTime, deletionTime) there can only be one host in the datastore with this name.
|
||||
* However, there can be many hosts with the same name and non-overlapping lifetimes.
|
||||
*/
|
||||
// TODO(b/25644770): Backfill this index. Until that's done, don't rely on it!
|
||||
@Index
|
||||
@XmlTransient
|
||||
String fullyQualifiedHostName;
|
||||
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@Index
|
||||
@XmlTransient
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
/** The superordinate domain of this host, or null if this is an external host. */
|
||||
@Index
|
||||
@IgnoreSave(IfNull.class)
|
||||
@XmlTransient
|
||||
Ref<DomainResource> superordinateDomain;
|
||||
|
||||
/**
|
||||
* The most recent time that the superordinate domain was changed, or null if this host is
|
||||
* external.
|
||||
*/
|
||||
@XmlTransient
|
||||
DateTime lastSuperordinateChange;
|
||||
|
||||
@XmlElement(name = "name")
|
||||
public String getFullyQualifiedHostName() {
|
||||
return fullyQualifiedHostName;
|
||||
}
|
||||
|
||||
public Ref<DomainResource> getSuperordinateDomain() {
|
||||
return superordinateDomain;
|
||||
}
|
||||
|
||||
@XmlElement(name = "addr")
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullToEmptyImmutableCopy(inetAddresses);
|
||||
}
|
||||
|
||||
public DateTime getLastSuperordinateChange() {
|
||||
return lastSuperordinateChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForeignKey() {
|
||||
return fullyQualifiedHostName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostResource cloneProjectedAtTime(DateTime now) {
|
||||
Builder builder = this.asBuilder();
|
||||
projectResourceOntoBuilderAtTime(this, builder, now);
|
||||
|
||||
if (superordinateDomain == null) {
|
||||
// If this was a subordinate host to a domain that was being transferred, there might be a
|
||||
// pending transfer still extant, so remove it.
|
||||
builder.setTransferData(null).removeStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
} else {
|
||||
// For hosts with superordinate domains, the client id, last transfer time, and transfer data
|
||||
// need to be read off the domain projected to the correct time.
|
||||
DomainResource domainAtTime = superordinateDomain.get().cloneProjectedAtTime(now);
|
||||
builder.setCurrentSponsorClientId(domainAtTime.getCurrentSponsorClientId());
|
||||
// If the superordinate domain's last transfer time is what is relevant, because the host's
|
||||
// superordinate domain was last changed less recently than the domain's last transfer, then
|
||||
// use the last transfer time on the domain.
|
||||
if (Optional.fromNullable(lastSuperordinateChange).or(START_OF_TIME)
|
||||
.isBefore(Optional.fromNullable(domainAtTime.getLastTransferTime()).or(START_OF_TIME))) {
|
||||
builder.setLastTransferTime(domainAtTime.getLastTransferTime());
|
||||
}
|
||||
// Copy the transfer status and data from the superordinate domain onto the host, because the
|
||||
// host's doesn't matter and the superordinate domain always has the canonical data.
|
||||
TransferData domainTransferData = domainAtTime.getTransferData();
|
||||
if (TransferStatus.PENDING.equals(domainTransferData.getTransferStatus())) {
|
||||
builder.addStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
} else {
|
||||
builder.removeStatusValue(StatusValue.PENDING_TRANSFER);
|
||||
}
|
||||
builder.setTransferData(domainTransferData);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder asBuilder() {
|
||||
return new Builder(clone(this));
|
||||
}
|
||||
|
||||
/** A builder for constructing {@link HostResource}, since it is immutable. */
|
||||
public static class Builder extends EppResource.Builder<HostResource, Builder> {
|
||||
public Builder() {}
|
||||
|
||||
private Builder(HostResource instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
||||
public Builder setFullyQualifiedHostName(String fullyQualifiedHostName) {
|
||||
getInstance().fullyQualifiedHostName = fullyQualifiedHostName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInetAddresses(ImmutableSet<InetAddress> inetAddresses) {
|
||||
getInstance().inetAddresses = inetAddresses;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLastSuperordinateChange(DateTime lastSuperordinateChange) {
|
||||
getInstance().lastSuperordinateChange = lastSuperordinateChange;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addInetAddresses(ImmutableSet<InetAddress> inetAddresses) {
|
||||
return setInetAddresses(ImmutableSet.copyOf(
|
||||
union(getInstance().getInetAddresses(), inetAddresses)));
|
||||
}
|
||||
|
||||
public Builder removeInetAddresses(ImmutableSet<InetAddress> inetAddresses) {
|
||||
return setInetAddresses(ImmutableSet.copyOf(
|
||||
difference(getInstance().getInetAddresses(), inetAddresses)));
|
||||
}
|
||||
|
||||
public Builder setSuperordinateDomain(Ref<DomainResource> superordinateDomain) {
|
||||
getInstance().superordinateDomain = superordinateDomain;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostResource build() {
|
||||
return super.build();
|
||||
}
|
||||
}
|
||||
}
|
69
java/google/registry/model/host/InetAddressAdapter.java
Normal file
69
java/google/registry/model/host/InetAddressAdapter.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed 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 com.google.domain.registry.model.host;
|
||||
|
||||
import com.google.common.net.InetAddresses;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
/**
|
||||
* Used by JAXB to convert InetAddress objects to and from AddrType objects, which are the
|
||||
* intermediate representations of IP addresses in EPP host commands.
|
||||
*/
|
||||
public final class InetAddressAdapter
|
||||
extends XmlAdapter<InetAddressAdapter.AddressShim, InetAddress> {
|
||||
|
||||
/**
|
||||
* Intermediate representation of an IP address on a host object. This object only exists
|
||||
* temporarily until it is converted by JAXB to and from an InetAddress via this adapter.
|
||||
*/
|
||||
static class AddressShim {
|
||||
@XmlValue
|
||||
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
|
||||
String ipAddress;
|
||||
|
||||
@XmlAttribute(name = "ip")
|
||||
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
|
||||
String ipVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddressShim marshal(InetAddress inetAddress) {
|
||||
AddressShim shim = new AddressShim();
|
||||
shim.ipAddress = InetAddresses.toAddrString(inetAddress);
|
||||
shim.ipVersion = (inetAddress instanceof Inet6Address) ? "v6" : "v4";
|
||||
return shim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress unmarshal(AddressShim shim) throws IpVersionMismatchException {
|
||||
InetAddress inetAddress = InetAddresses.forString(shim.ipAddress);
|
||||
// Enforce that "v6" is used iff the address is ipv6. (For ipv4, "v4" is allowed to be missing.)
|
||||
if (inetAddress instanceof Inet6Address != "v6".equals(shim.ipVersion)) {
|
||||
throw new IpVersionMismatchException();
|
||||
}
|
||||
return inetAddress;
|
||||
}
|
||||
|
||||
/** Exception for when the specified type of an address (v4/v6) doesn't match its actual type. */
|
||||
public static class IpVersionMismatchException extends Exception {}
|
||||
}
|
34
java/google/registry/model/host/package-info.java
Normal file
34
java/google/registry/model/host/package-info.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
@XmlSchema(
|
||||
namespace = "urn:ietf:params:xml:ns:host-1.0",
|
||||
xmlns = @XmlNs(prefix = "host", namespaceURI = "urn:ietf:params:xml:ns:host-1.0"),
|
||||
elementFormDefault = XmlNsForm.QUALIFIED)
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlJavaTypeAdapters({
|
||||
@XmlJavaTypeAdapter(UtcDateTimeAdapter.class),
|
||||
@XmlJavaTypeAdapter(InetAddressAdapter.class)})
|
||||
package com.google.domain.registry.model.host;
|
||||
|
||||
import com.google.domain.registry.xml.UtcDateTimeAdapter;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlNs;
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue