mirror of
https://github.com/google/nomulus.git
synced 2025-06-28 07:13:34 +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
133
java/google/registry/model/index/DomainApplicationIndex.java
Normal file
133
java/google/registry/model/index/DomainApplicationIndex.java
Normal file
|
@ -0,0 +1,133 @@
|
|||
// 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.index;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static com.google.domain.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
||||
import static com.google.domain.registry.util.CollectionUtils.isNullOrEmpty;
|
||||
import static com.google.domain.registry.util.DateTimeUtils.latestOf;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.model.BackupGroupRoot;
|
||||
import com.google.domain.registry.model.domain.DomainApplication;
|
||||
import com.google.domain.registry.util.CollectionUtils;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Ref;
|
||||
import com.googlecode.objectify.annotation.Cache;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Entity for tracking all domain applications with a given fully qualified domain name. Since this
|
||||
* resource is always kept up to date as additional domain applications are created, it is never
|
||||
* necessary to query them explicitly from Datastore.
|
||||
*/
|
||||
@Entity
|
||||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
public class DomainApplicationIndex extends BackupGroupRoot {
|
||||
|
||||
@Id
|
||||
String fullyQualifiedDomainName;
|
||||
|
||||
/**
|
||||
* A set of all domain applications with this fully qualified domain name. Never null or empty.
|
||||
*/
|
||||
Set<Ref<DomainApplication>> references;
|
||||
|
||||
/** Returns a cloned list of all references on this index. */
|
||||
public ImmutableSet<Ref<DomainApplication>> getReferences() {
|
||||
return ImmutableSet.copyOf(references);
|
||||
}
|
||||
|
||||
public String getFullyQualifiedDomainName() {
|
||||
return fullyQualifiedDomainName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DomainApplicationIndex with the specified list of references. Only use this method
|
||||
* for data migrations. You probably want {@link #createUpdatedInstance}.
|
||||
*/
|
||||
public static DomainApplicationIndex createWithSpecifiedReferences(
|
||||
String fullyQualifiedDomainName,
|
||||
ImmutableSet<Ref<DomainApplication>> references) {
|
||||
checkArgument(!isNullOrEmpty(fullyQualifiedDomainName),
|
||||
"fullyQualifiedDomainName must not be null or empty.");
|
||||
checkArgument(!isNullOrEmpty(references), "References must not be null or empty.");
|
||||
DomainApplicationIndex instance = new DomainApplicationIndex();
|
||||
instance.fullyQualifiedDomainName = fullyQualifiedDomainName;
|
||||
instance.references = references;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Key<DomainApplicationIndex> createKey(DomainApplication application) {
|
||||
return Key.create(DomainApplicationIndex.class, application.getFullyQualifiedDomainName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterable of all DomainApplications for the given fully qualified domain name that
|
||||
* do not have a deletion time before the supplied DateTime.
|
||||
*/
|
||||
public static Iterable<DomainApplication> loadActiveApplicationsByDomainName(
|
||||
String fullyQualifiedDomainName, DateTime now) {
|
||||
DomainApplicationIndex index = load(fullyQualifiedDomainName);
|
||||
if (index == null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
ImmutableSet.Builder<DomainApplication> apps = new ImmutableSet.Builder<>();
|
||||
for (DomainApplication app : ofy().load().refs(index.getReferences()).values()) {
|
||||
DateTime forwardedNow = latestOf(now, app.getUpdateAutoTimestamp().getTimestamp());
|
||||
if (app.getDeletionTime().isAfter(forwardedNow)) {
|
||||
apps.add(app.cloneProjectedAtTime(forwardedNow));
|
||||
}
|
||||
}
|
||||
return apps.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DomainApplicationIndex for the given fully qualified domain name. Note that this
|
||||
* can return null if there are no domain applications for this fully qualified domain name.
|
||||
*/
|
||||
@Nullable
|
||||
public static DomainApplicationIndex load(String fullyQualifiedDomainName) {
|
||||
return ofy()
|
||||
.load()
|
||||
.type(DomainApplicationIndex.class)
|
||||
.id(fullyQualifiedDomainName)
|
||||
.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a new DomainApplicationIndex for this resource or updates the existing one. This is
|
||||
* the preferred method for creating an instance of DomainApplicationIndex because this performs
|
||||
* the correct merging logic to add the given domain application to an existing index if there
|
||||
* is one.
|
||||
*/
|
||||
public static DomainApplicationIndex createUpdatedInstance(DomainApplication application) {
|
||||
DomainApplicationIndex existing = load(application.getFullyQualifiedDomainName());
|
||||
ImmutableSet<Ref<DomainApplication>> newReferences = CollectionUtils.union(
|
||||
(existing == null ? ImmutableSet.<Ref<DomainApplication>>of() : existing.getReferences()),
|
||||
Ref.create(application));
|
||||
return createWithSpecifiedReferences(application.getFullyQualifiedDomainName(), newReferences);
|
||||
}
|
||||
}
|
76
java/google/registry/model/index/EppResourceIndex.java
Normal file
76
java/google/registry/model/index/EppResourceIndex.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
// 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.index;
|
||||
|
||||
import static com.google.domain.registry.util.TypeUtils.instantiate;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.domain.registry.model.BackupGroupRoot;
|
||||
import com.google.domain.registry.model.EppResource;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Ref;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
import com.googlecode.objectify.annotation.Parent;
|
||||
|
||||
/** An index that allows for quick enumeration of all EppResource entities (e.g. via map reduce). */
|
||||
@Entity
|
||||
public class EppResourceIndex extends BackupGroupRoot {
|
||||
|
||||
@Id
|
||||
String id;
|
||||
|
||||
@Parent
|
||||
Key<EppResourceIndexBucket> bucket;
|
||||
|
||||
Ref<? extends EppResource> reference;
|
||||
|
||||
@Index
|
||||
String kind;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public Ref<? extends EppResource> getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public Key<EppResourceIndexBucket> getBucket() {
|
||||
return bucket;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static <T extends EppResource> EppResourceIndex create(
|
||||
Key<EppResourceIndexBucket> bucket, Key<T> resourceKey) {
|
||||
EppResourceIndex instance = instantiate(EppResourceIndex.class);
|
||||
instance.reference = Ref.create(resourceKey);
|
||||
instance.kind = resourceKey.getKind();
|
||||
instance.id = resourceKey.getString(); // creates a web-safe key string
|
||||
instance.bucket = bucket;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static <T extends EppResource> EppResourceIndex create(Key<T> resourceKey) {
|
||||
return create(EppResourceIndexBucket.getBucketKey(resourceKey), resourceKey);
|
||||
}
|
||||
}
|
66
java/google/registry/model/index/EppResourceIndexBucket.java
Normal file
66
java/google/registry/model/index/EppResourceIndexBucket.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
// 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.index;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.domain.registry.config.RegistryEnvironment;
|
||||
import com.google.domain.registry.model.EppResource;
|
||||
import com.google.domain.registry.model.ImmutableObject;
|
||||
import com.google.domain.registry.model.annotations.VirtualEntity;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
|
||||
/** A virtual entity to represent buckets to which EppResourceIndex objects are randomly added. */
|
||||
@Entity
|
||||
@VirtualEntity
|
||||
public class EppResourceIndexBucket extends ImmutableObject {
|
||||
|
||||
@Id
|
||||
private long bucketId;
|
||||
|
||||
/**
|
||||
* Deterministic function that returns a bucket id based on the resource's roid.
|
||||
* NB: At the moment, nothing depends on this being deterministic, so we have the ability to
|
||||
* change the number of buckets and utilize a random distribution once we do.
|
||||
*/
|
||||
private static long getBucketIdFromEppResource(Key<? extends EppResource> resourceKey) {
|
||||
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount();
|
||||
// IDs can't be 0, so add 1 to the hash.
|
||||
return Hashing.consistentHash(resourceKey.getName().hashCode(), numBuckets) + 1;
|
||||
}
|
||||
|
||||
/** Gets a bucket key as a function of an EppResource to be indexed. */
|
||||
public static Key<EppResourceIndexBucket> getBucketKey(Key<? extends EppResource> resourceKey) {
|
||||
return Key.create(EppResourceIndexBucket.class, getBucketIdFromEppResource(resourceKey));
|
||||
}
|
||||
|
||||
/** Gets the specified numbered bucket key. */
|
||||
public static Key<EppResourceIndexBucket> getBucketKey(int bucketId) {
|
||||
return Key.create(EppResourceIndexBucket.class, bucketId);
|
||||
}
|
||||
|
||||
/** Returns the keys to all buckets. */
|
||||
public static Iterable<Key<EppResourceIndexBucket>> getAllBuckets() {
|
||||
ImmutableList.Builder<Key<EppResourceIndexBucket>> builder = new ImmutableList.Builder<>();
|
||||
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount();
|
||||
for (int bucketId = 1; bucketId <= numBuckets; bucketId++) {
|
||||
builder.add(getBucketKey(bucketId));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
169
java/google/registry/model/index/ForeignKeyIndex.java
Normal file
169
java/google/registry/model/index/ForeignKeyIndex.java
Normal file
|
@ -0,0 +1,169 @@
|
|||
// 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.index;
|
||||
|
||||
import static com.google.common.collect.Maps.filterValues;
|
||||
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static com.google.domain.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
|
||||
import static com.google.domain.registry.util.TypeUtils.instantiate;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.domain.registry.model.BackupGroupRoot;
|
||||
import com.google.domain.registry.model.EppResource;
|
||||
import com.google.domain.registry.model.contact.ContactResource;
|
||||
import com.google.domain.registry.model.domain.DomainResource;
|
||||
import com.google.domain.registry.model.host.HostResource;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Ref;
|
||||
import com.googlecode.objectify.annotation.Cache;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Index;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class to map a foreign key to the active instance of {@link EppResource} whose unique id matches
|
||||
* the foreign key string. The instance is never deleted, but it is updated if a newer entity
|
||||
* becomes the active entity.
|
||||
*/
|
||||
public abstract class ForeignKeyIndex<E extends EppResource> extends BackupGroupRoot {
|
||||
|
||||
/** The {@link ForeignKeyIndex} type for {@link ContactResource} entities. */
|
||||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
@Entity
|
||||
public static class ForeignKeyContactIndex extends ForeignKeyIndex<ContactResource> {}
|
||||
|
||||
/** The {@link ForeignKeyIndex} type for {@link DomainResource} entities. */
|
||||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
@Entity
|
||||
public static class ForeignKeyDomainIndex extends ForeignKeyIndex<DomainResource> {}
|
||||
|
||||
/** The {@link ForeignKeyIndex} type for {@link HostResource} entities. */
|
||||
@Cache(expirationSeconds = RECOMMENDED_MEMCACHE_EXPIRATION)
|
||||
@Entity
|
||||
public static class ForeignKeyHostIndex extends ForeignKeyIndex<HostResource> {}
|
||||
|
||||
private static final Map<
|
||||
Class<? extends EppResource>,
|
||||
Class<? extends ForeignKeyIndex<?>>> RESOURCE_CLASS_TO_FKI_CLASS =
|
||||
ImmutableMap.<Class<? extends EppResource>, Class<? extends ForeignKeyIndex<?>>>of(
|
||||
ContactResource.class, ForeignKeyContactIndex.class,
|
||||
DomainResource.class, ForeignKeyDomainIndex.class,
|
||||
HostResource.class, ForeignKeyHostIndex.class);
|
||||
|
||||
@Id
|
||||
String foreignKey;
|
||||
|
||||
/**
|
||||
* The deletion time of this {@link ForeignKeyIndex}.
|
||||
*
|
||||
* <p>This will generally be equal to the deletion time of {@link #topReference}. However, in the
|
||||
* case of a {@link HostResource} that was renamed, this field will hold the time of the rename.
|
||||
*/
|
||||
@Index
|
||||
DateTime deletionTime;
|
||||
|
||||
/**
|
||||
* The referenced resource.
|
||||
*
|
||||
* <p>This field holds the only reference. It is named "topReference" for historical reasons.
|
||||
*/
|
||||
Ref<E> topReference;
|
||||
|
||||
public String getForeignKey() {
|
||||
return foreignKey;
|
||||
}
|
||||
|
||||
public DateTime getDeletionTime() {
|
||||
return deletionTime;
|
||||
}
|
||||
|
||||
public Ref<E> getReference() {
|
||||
return topReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link ForeignKeyIndex} instance for a resource, expiring at a specified time.
|
||||
*/
|
||||
public static <E extends EppResource> ForeignKeyIndex<E> create(
|
||||
E resource, DateTime deletionTime) {
|
||||
ForeignKeyIndex<E> instance = instantiate(RESOURCE_CLASS_TO_FKI_CLASS.get(resource.getClass()));
|
||||
instance.topReference = Ref.create(resource);
|
||||
instance.foreignKey = resource.getForeignKey();
|
||||
instance.deletionTime = deletionTime;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** Create a {@link ForeignKeyIndex} key for a resource. */
|
||||
public static Key<ForeignKeyIndex<?>> createKey(EppResource resource) {
|
||||
return Key.<ForeignKeyIndex<?>>create(
|
||||
RESOURCE_CLASS_TO_FKI_CLASS.get(resource.getClass()), resource.getForeignKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a reference to an {@link EppResource} from the datastore by foreign key.
|
||||
*
|
||||
* <p>Returns absent if no foreign key index with this foreign key was ever created, or if the
|
||||
* most recently created foreign key index was deleted before time "now". This method does not
|
||||
* actually check that the referenced resource actually exists. However, for normal epp resources,
|
||||
* it is safe to assume that the referenced resource exists if the foreign key index does.
|
||||
*
|
||||
* @param clazz the resource type to load
|
||||
* @param foreignKey id to match
|
||||
* @param now the current logical time to use when checking for soft deletion of the foreign key
|
||||
* index
|
||||
*/
|
||||
public static <E extends EppResource> Ref<E> loadAndGetReference(
|
||||
Class<E> clazz, String foreignKey, DateTime now) {
|
||||
ForeignKeyIndex<E> index = load(clazz, foreignKey, now);
|
||||
return (index == null) ? null : index.getReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a {@link ForeignKeyIndex} by class and id string that is active at or after the specified
|
||||
* moment in time.
|
||||
*
|
||||
* <p>This will return null if the {@link ForeignKeyIndex} doesn't exist or has been soft deleted.
|
||||
*/
|
||||
public static <E extends EppResource> ForeignKeyIndex<E> load(
|
||||
Class<E> clazz, String foreignKey, DateTime now) {
|
||||
return load(clazz, ImmutableList.of(foreignKey), now).get(foreignKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a list of {@link ForeignKeyIndex} instances by class and id strings that are active at or
|
||||
* after the specified moment in time.
|
||||
*
|
||||
* <p>The returned map will omit any keys for which the {@link ForeignKeyIndex} doesn't exist or
|
||||
* has been soft deleted.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <E extends EppResource> Map<String, ForeignKeyIndex<E>> load(
|
||||
Class<E> clazz, Iterable<String> foreignKeys, final DateTime now) {
|
||||
return (Map<String, ForeignKeyIndex<E>>) filterValues(
|
||||
ofy().load().type(RESOURCE_CLASS_TO_FKI_CLASS.get(clazz)).ids(foreignKeys),
|
||||
new Predicate<ForeignKeyIndex<?>>() {
|
||||
@Override
|
||||
public boolean apply(ForeignKeyIndex<?> fki) {
|
||||
return now.isBefore(fki.deletionTime);
|
||||
}});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue