Change PackagePromotion to BulkPricingPackage (#2096)

* Change PackagePromotion to BulkPricingPackage

* More name changes

* Fix some test names

* Change token type "BULK" to "BULK_PRICING"

* Fix missed token_type reference

* Add todo to remove package type
This commit is contained in:
sarahcaseybot
2023-08-22 16:39:24 -04:00
committed by GitHub
parent f59c387b9c
commit 1dcbc9e0cb
43 changed files with 879 additions and 836 deletions
@@ -0,0 +1,246 @@
// Copyright 2022 The Nomulus 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 google.registry.batch;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.common.primitives.Ints;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.BulkPricingPackage;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
import google.registry.request.Action.Service;
import google.registry.request.auth.Auth;
import google.registry.ui.server.SendEmailUtils;
import google.registry.util.Clock;
import java.util.Optional;
import javax.inject.Inject;
import org.joda.time.Days;
/**
* An action that checks all {@link BulkPricingPackage} objects for compliance with their max create
* limit.
*/
@Action(
service = Service.BACKEND,
path = CheckBulkComplianceAction.PATH,
auth = Auth.AUTH_API_ADMIN)
public class CheckBulkComplianceAction implements Runnable {
public static final String PATH = "/_dr/task/checkBulkCompliance";
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SendEmailUtils sendEmailUtils;
private final Clock clock;
private final String bulkPricingPackageCreateLimitEmailSubject;
private final String bulkPricingPackageDomainLimitWarningEmailSubject;
private final String bulkPricingPackageDomainLimitUpgradeEmailSubject;
private final String bulkPricingPackageCreateLimitEmailBody;
private final String bulkPricingPackageDomainLimitWarningEmailBody;
private final String bulkPricingPackageDomainLimitUpgradeEmailBody;
private final String registrySupportEmail;
private static final int THIRTY_DAYS = 30;
private static final int FORTY_DAYS = 40;
@Inject
public CheckBulkComplianceAction(
SendEmailUtils sendEmailUtils,
Clock clock,
@Config("bulkPricingPackageCreateLimitEmailSubject")
String bulkPricingPackageCreateLimitEmailSubject,
@Config("bulkPricingPackageDomainLimitWarningEmailSubject")
String bulkPricingPackageDomainLimitWarningEmailSubject,
@Config("bulkPricingPackageDomainLimitUpgradeEmailSubject")
String bulkPricingPackageDomainLimitUpgradeEmailSubject,
@Config("bulkPricingPackageCreateLimitEmailBody")
String bulkPricingPackageCreateLimitEmailBody,
@Config("bulkPricingPackageDomainLimitWarningEmailBody")
String bulkPricingPackageDomainLimitWarningEmailBody,
@Config("bulkPricingPackageDomainLimitUpgradeEmailBody")
String bulkPricingPackageDomainLimitUpgradeEmailBody,
@Config("registrySupportEmail") String registrySupportEmail) {
this.sendEmailUtils = sendEmailUtils;
this.clock = clock;
this.bulkPricingPackageCreateLimitEmailSubject = bulkPricingPackageCreateLimitEmailSubject;
this.bulkPricingPackageDomainLimitWarningEmailSubject =
bulkPricingPackageDomainLimitWarningEmailSubject;
this.bulkPricingPackageDomainLimitUpgradeEmailSubject =
bulkPricingPackageDomainLimitUpgradeEmailSubject;
this.bulkPricingPackageCreateLimitEmailBody = bulkPricingPackageCreateLimitEmailBody;
this.bulkPricingPackageDomainLimitWarningEmailBody =
bulkPricingPackageDomainLimitWarningEmailBody;
this.bulkPricingPackageDomainLimitUpgradeEmailBody =
bulkPricingPackageDomainLimitUpgradeEmailBody;
this.registrySupportEmail = registrySupportEmail;
}
@Override
public void run() {
tm().transact(this::checkBulkPackages);
}
private void checkBulkPackages() {
ImmutableList<BulkPricingPackage> bulkPricingPackages =
tm().loadAllOf(BulkPricingPackage.class);
ImmutableMap.Builder<BulkPricingPackage, Long> bulkPricingPackagesOverCreateLimitBuilder =
new ImmutableMap.Builder<>();
ImmutableMap.Builder<BulkPricingPackage, Long>
bulkPricingPackagesOverActiveDomainsLimitBuilder = new ImmutableMap.Builder<>();
for (BulkPricingPackage bulkPricingPackage : bulkPricingPackages) {
Long creates =
(Long)
tm().query(
"SELECT COUNT(*) FROM DomainHistory WHERE current_package_token ="
+ " :token AND modificationTime >= :lastBilling AND type ="
+ " 'DOMAIN_CREATE'")
.setParameter("token", bulkPricingPackage.getToken().getKey().toString())
.setParameter(
"lastBilling", bulkPricingPackage.getNextBillingDate().minusYears(1))
.getSingleResult();
if (creates > bulkPricingPackage.getMaxCreates()) {
long overage = creates - bulkPricingPackage.getMaxCreates();
logger.atInfo().log(
"Bulk pricing package with bulk token %s has exceeded their max domain creation limit"
+ " by %d name(s).",
bulkPricingPackage.getToken().getKey(), overage);
bulkPricingPackagesOverCreateLimitBuilder.put(bulkPricingPackage, creates);
}
Long activeDomains =
tm().query(
"SELECT COUNT(*) FROM Domain WHERE currentBulkToken = :token"
+ " AND deletionTime = :endOfTime",
Long.class)
.setParameter("token", bulkPricingPackage.getToken())
.setParameter("endOfTime", END_OF_TIME)
.getSingleResult();
if (activeDomains > bulkPricingPackage.getMaxDomains()) {
int overage = Ints.saturatedCast(activeDomains) - bulkPricingPackage.getMaxDomains();
logger.atInfo().log(
"Bulk pricing package with bulk token %s has exceed their max active domains limit by"
+ " %d name(s).",
bulkPricingPackage.getToken().getKey(), overage);
bulkPricingPackagesOverActiveDomainsLimitBuilder.put(bulkPricingPackage, activeDomains);
}
}
handleBulkPricingPackageCreationOverage(bulkPricingPackagesOverCreateLimitBuilder.build());
handleActiveDomainOverage(bulkPricingPackagesOverActiveDomainsLimitBuilder.build());
}
private void handleBulkPricingPackageCreationOverage(
ImmutableMap<BulkPricingPackage, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no bulk pricing packages over their create limit.");
return;
}
logger.atInfo().log(
"Found %d bulk pricing packages over their create limit.", overageList.size());
for (BulkPricingPackage bulkPricingPackage : overageList.keySet()) {
AllocationToken bulkToken = tm().loadByKey(bulkPricingPackage.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(bulkToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
bulkPricingPackageCreateLimitEmailBody,
bulkPricingPackage.getId(),
bulkToken.getToken(),
registrar.get().getRegistrarName(),
bulkPricingPackage.getMaxCreates(),
overageList.get(bulkPricingPackage));
sendNotification(
bulkToken, bulkPricingPackageCreateLimitEmailSubject, body, registrar.get());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for bulk token %s", bulkToken));
}
}
}
private void handleActiveDomainOverage(ImmutableMap<BulkPricingPackage, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no bulk pricing packages over their active domains limit.");
return;
}
logger.atInfo().log(
"Found %d bulk pricing packages over their active domains limit.", overageList.size());
for (BulkPricingPackage bulkPricingPackage : overageList.keySet()) {
int daysSinceLastNotification =
bulkPricingPackage
.getLastNotificationSent()
.map(sentDate -> Days.daysBetween(sentDate, clock.nowUtc()).getDays())
.orElse(Integer.MAX_VALUE);
if (daysSinceLastNotification < THIRTY_DAYS) {
// Don't send an email if notification was already sent within the last 30
// days
continue;
} else if (daysSinceLastNotification < FORTY_DAYS) {
// Send an upgrade email if last email was between 30 and 40 days ago
sendActiveDomainOverageEmail(
/* warning= */ false, bulkPricingPackage, overageList.get(bulkPricingPackage));
} else {
// Send a warning email
sendActiveDomainOverageEmail(
/* warning= */ true, bulkPricingPackage, overageList.get(bulkPricingPackage));
}
}
}
private void sendActiveDomainOverageEmail(
boolean warning, BulkPricingPackage bulkPricingPackage, long activeDomains) {
String emailSubject =
warning
? bulkPricingPackageDomainLimitWarningEmailSubject
: bulkPricingPackageDomainLimitUpgradeEmailSubject;
String emailTemplate =
warning
? bulkPricingPackageDomainLimitWarningEmailBody
: bulkPricingPackageDomainLimitUpgradeEmailBody;
AllocationToken bulkToken = tm().loadByKey(bulkPricingPackage.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(bulkToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
emailTemplate,
bulkPricingPackage.getId(),
bulkToken.getToken(),
registrar.get().getRegistrarName(),
bulkPricingPackage.getMaxDomains(),
activeDomains);
sendNotification(bulkToken, emailSubject, body, registrar.get());
tm().put(bulkPricingPackage.asBuilder().setLastNotificationSent(clock.nowUtc()).build());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for bulk token %s", bulkToken));
}
}
private void sendNotification(
AllocationToken bulkToken, String subject, String body, Registrar registrar) {
logger.atInfo().log(
String.format(
"Compliance email sent to support regarding the %s registrar and the bulk pricing"
+ " package with token %s.",
registrar.getRegistrarName(), bulkToken.getToken()));
sendEmailUtils.sendEmail(subject, body, ImmutableList.of(registrySupportEmail));
}
}
@@ -1,226 +0,0 @@
// Copyright 2022 The Nomulus 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 google.registry.batch;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.common.primitives.Ints;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
import google.registry.request.Action.Service;
import google.registry.request.auth.Auth;
import google.registry.ui.server.SendEmailUtils;
import google.registry.util.Clock;
import java.util.Optional;
import javax.inject.Inject;
import org.joda.time.Days;
/**
* An action that checks all {@link PackagePromotion} objects for compliance with their max create
* limit.
*/
@Action(
service = Service.BACKEND,
path = CheckPackagesComplianceAction.PATH,
auth = Auth.AUTH_API_ADMIN)
public class CheckPackagesComplianceAction implements Runnable {
public static final String PATH = "/_dr/task/checkPackagesCompliance";
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SendEmailUtils sendEmailUtils;
private final Clock clock;
private final String packageCreateLimitEmailSubject;
private final String packageDomainLimitWarningEmailSubject;
private final String packageDomainLimitUpgradeEmailSubject;
private final String packageCreateLimitEmailBody;
private final String packageDomainLimitWarningEmailBody;
private final String packageDomainLimitUpgradeEmailBody;
private final String registrySupportEmail;
private static final int THIRTY_DAYS = 30;
private static final int FORTY_DAYS = 40;
@Inject
public CheckPackagesComplianceAction(
SendEmailUtils sendEmailUtils,
Clock clock,
@Config("packageCreateLimitEmailSubject") String packageCreateLimitEmailSubject,
@Config("packageDomainLimitWarningEmailSubject") String packageDomainLimitWarningEmailSubject,
@Config("packageDomainLimitUpgradeEmailSubject") String packageDomainLimitUpgradeEmailSubject,
@Config("packageCreateLimitEmailBody") String packageCreateLimitEmailBody,
@Config("packageDomainLimitWarningEmailBody") String packageDomainLimitWarningEmailBody,
@Config("packageDomainLimitUpgradeEmailBody") String packageDomainLimitUpgradeEmailBody,
@Config("registrySupportEmail") String registrySupportEmail) {
this.sendEmailUtils = sendEmailUtils;
this.clock = clock;
this.packageCreateLimitEmailSubject = packageCreateLimitEmailSubject;
this.packageDomainLimitWarningEmailSubject = packageDomainLimitWarningEmailSubject;
this.packageDomainLimitUpgradeEmailSubject = packageDomainLimitUpgradeEmailSubject;
this.packageCreateLimitEmailBody = packageCreateLimitEmailBody;
this.packageDomainLimitWarningEmailBody = packageDomainLimitWarningEmailBody;
this.packageDomainLimitUpgradeEmailBody = packageDomainLimitUpgradeEmailBody;
this.registrySupportEmail = registrySupportEmail;
}
@Override
public void run() {
tm().transact(this::checkPackages);
}
private void checkPackages() {
ImmutableList<PackagePromotion> packages = tm().loadAllOf(PackagePromotion.class);
ImmutableMap.Builder<PackagePromotion, Long> packagesOverCreateLimitBuilder =
new ImmutableMap.Builder<>();
ImmutableMap.Builder<PackagePromotion, Long> packagesOverActiveDomainsLimitBuilder =
new ImmutableMap.Builder<>();
for (PackagePromotion packagePromo : packages) {
Long creates =
(Long)
tm().query(
"SELECT COUNT(*) FROM DomainHistory WHERE current_package_token ="
+ " :token AND modificationTime >= :lastBilling AND type ="
+ " 'DOMAIN_CREATE'")
.setParameter("token", packagePromo.getToken().getKey().toString())
.setParameter("lastBilling", packagePromo.getNextBillingDate().minusYears(1))
.getSingleResult();
if (creates > packagePromo.getMaxCreates()) {
long overage = creates - packagePromo.getMaxCreates();
logger.atInfo().log(
"Package with package token %s has exceeded their max domain creation limit"
+ " by %d name(s).",
packagePromo.getToken().getKey(), overage);
packagesOverCreateLimitBuilder.put(packagePromo, creates);
}
Long activeDomains =
tm().query(
"SELECT COUNT(*) FROM Domain WHERE currentPackageToken = :token"
+ " AND deletionTime = :endOfTime",
Long.class)
.setParameter("token", packagePromo.getToken())
.setParameter("endOfTime", END_OF_TIME)
.getSingleResult();
if (activeDomains > packagePromo.getMaxDomains()) {
int overage = Ints.saturatedCast(activeDomains) - packagePromo.getMaxDomains();
logger.atInfo().log(
"Package with package token %s has exceed their max active domains limit by"
+ " %d name(s).",
packagePromo.getToken().getKey(), overage);
packagesOverActiveDomainsLimitBuilder.put(packagePromo, activeDomains);
}
}
handlePackageCreationOverage(packagesOverCreateLimitBuilder.build());
handleActiveDomainOverage(packagesOverActiveDomainsLimitBuilder.build());
}
private void handlePackageCreationOverage(ImmutableMap<PackagePromotion, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no packages over their create limit.");
return;
}
logger.atInfo().log("Found %d packages over their create limit.", overageList.size());
for (PackagePromotion packagePromotion : overageList.keySet()) {
AllocationToken packageToken = tm().loadByKey(packagePromotion.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(packageToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
packageCreateLimitEmailBody,
packagePromotion.getId(),
packageToken.getToken(),
registrar.get().getRegistrarName(),
packagePromotion.getMaxCreates(),
overageList.get(packagePromotion));
sendNotification(packageToken, packageCreateLimitEmailSubject, body, registrar.get());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for package token %s", packageToken));
}
}
}
private void handleActiveDomainOverage(ImmutableMap<PackagePromotion, Long> overageList) {
if (overageList.isEmpty()) {
logger.atInfo().log("Found no packages over their active domains limit.");
return;
}
logger.atInfo().log("Found %d packages over their active domains limit.", overageList.size());
for (PackagePromotion packagePromotion : overageList.keySet()) {
int daysSinceLastNotification =
packagePromotion
.getLastNotificationSent()
.map(sentDate -> Days.daysBetween(sentDate, clock.nowUtc()).getDays())
.orElse(Integer.MAX_VALUE);
if (daysSinceLastNotification < THIRTY_DAYS) {
// Don't send an email if notification was already sent within the last 30
// days
continue;
} else if (daysSinceLastNotification < FORTY_DAYS) {
// Send an upgrade email if last email was between 30 and 40 days ago
sendActiveDomainOverageEmail(
/* warning= */ false, packagePromotion, overageList.get(packagePromotion));
} else {
// Send a warning email
sendActiveDomainOverageEmail(
/* warning= */ true, packagePromotion, overageList.get(packagePromotion));
}
}
}
private void sendActiveDomainOverageEmail(
boolean warning, PackagePromotion packagePromotion, long activeDomains) {
String emailSubject =
warning ? packageDomainLimitWarningEmailSubject : packageDomainLimitUpgradeEmailSubject;
String emailTemplate =
warning ? packageDomainLimitWarningEmailBody : packageDomainLimitUpgradeEmailBody;
AllocationToken packageToken = tm().loadByKey(packagePromotion.getToken());
Optional<Registrar> registrar =
Registrar.loadByRegistrarIdCached(
Iterables.getOnlyElement(packageToken.getAllowedRegistrarIds()));
if (registrar.isPresent()) {
String body =
String.format(
emailTemplate,
packagePromotion.getId(),
packageToken.getToken(),
registrar.get().getRegistrarName(),
packagePromotion.getMaxDomains(),
activeDomains);
sendNotification(packageToken, emailSubject, body, registrar.get());
tm().put(packagePromotion.asBuilder().setLastNotificationSent(clock.nowUtc()).build());
} else {
throw new IllegalStateException(
String.format("Could not find registrar for package token %s", packageToken));
}
}
private void sendNotification(
AllocationToken packageToken, String subject, String body, Registrar registrar) {
logger.atInfo().log(
String.format(
"Compliance email sent to support regarding the %s registrar and the package with token"
+ " %s.",
registrar.getRegistrarName(), packageToken.getToken()));
sendEmailUtils.sendEmail(subject, body, ImmutableList.of(registrySupportEmail));
}
}
@@ -1371,41 +1371,45 @@ public final class RegistryConfig {
}
@Provides
@Config("packageCreateLimitEmailSubject")
public static String providePackageCreateLimitEmailSubject(RegistryConfigSettings config) {
return config.packageMonitoring.packageCreateLimitEmailSubject;
}
@Provides
@Config("packageCreateLimitEmailBody")
public static String providePackageCreateLimitEmailBody(RegistryConfigSettings config) {
return config.packageMonitoring.packageCreateLimitEmailBody;
}
@Provides
@Config("packageDomainLimitWarningEmailSubject")
public static String providePackageDomainLimitWarningEmailSubject(
@Config("bulkPricingPackageCreateLimitEmailSubject")
public static String provideBulkPricingPackageCreateLimitEmailSubject(
RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitWarningEmailSubject;
return config.bulkPricingPackageMonitoring.bulkPricingPackageCreateLimitEmailSubject;
}
@Provides
@Config("packageDomainLimitWarningEmailBody")
public static String providePackageDomainLimitWarningEmailBody(RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitWarningEmailBody;
}
@Provides
@Config("packageDomainLimitUpgradeEmailSubject")
public static String providePackageDomainLimitUpgradeEmailSubject(
@Config("bulkPricingPackageCreateLimitEmailBody")
public static String provideBulkPricingPackageCreateLimitEmailBody(
RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitUpgradeEmailSubject;
return config.bulkPricingPackageMonitoring.bulkPricingPackageCreateLimitEmailBody;
}
@Provides
@Config("packageDomainLimitUpgradeEmailBody")
public static String providePackageDomainLimitUpgradeEmailBody(RegistryConfigSettings config) {
return config.packageMonitoring.packageDomainLimitUpgradeEmailBody;
@Config("bulkPricingPackageDomainLimitWarningEmailSubject")
public static String provideBulkPricingPackageDomainLimitWarningEmailSubject(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitWarningEmailSubject;
}
@Provides
@Config("bulkPricingPackageDomainLimitWarningEmailBody")
public static String provideBulkPricingPackageDomainLimitWarningEmailBody(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitWarningEmailBody;
}
@Provides
@Config("bulkPricingPackageDomainLimitUpgradeEmailSubject")
public static String provideBulkPricingPackageDomainLimitUpgradeEmailSubject(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitUpgradeEmailSubject;
}
@Provides
@Config("bulkPricingPackageDomainLimitUpgradeEmailBody")
public static String provideBulkPricingPackageDomainLimitUpgradeEmailBody(
RegistryConfigSettings config) {
return config.bulkPricingPackageMonitoring.bulkPricingPackageDomainLimitUpgradeEmailBody;
}
private static String formatComments(String text) {
@@ -42,7 +42,7 @@ public class RegistryConfigSettings {
public SslCertificateValidation sslCertificateValidation;
public ContactHistory contactHistory;
public DnsUpdate dnsUpdate;
public PackageMonitoring packageMonitoring;
public BulkPricingPackageMonitoring bulkPricingPackageMonitoring;
/** Configuration options that apply to the entire GCP project. */
public static class GcpProject {
@@ -253,13 +253,13 @@ public class RegistryConfigSettings {
public String registryCcEmail;
}
/** Configuration for package compliance monitoring. */
public static class PackageMonitoring {
public String packageCreateLimitEmailSubject;
public String packageCreateLimitEmailBody;
public String packageDomainLimitWarningEmailSubject;
public String packageDomainLimitWarningEmailBody;
public String packageDomainLimitUpgradeEmailSubject;
public String packageDomainLimitUpgradeEmailBody;
/** Configuration for bulk pricing package compliance monitoring. */
public static class BulkPricingPackageMonitoring {
public String bulkPricingPackageCreateLimitEmailSubject;
public String bulkPricingPackageCreateLimitEmailBody;
public String bulkPricingPackageDomainLimitWarningEmailSubject;
public String bulkPricingPackageDomainLimitWarningEmailBody;
public String bulkPricingPackageDomainLimitUpgradeEmailSubject;
public String bulkPricingPackageDomainLimitUpgradeEmailBody;
}
}
@@ -559,55 +559,55 @@ sslCertificateValidation:
- secp256r1
- secp384r1
# Configuration options for the package compliance monitoring
packageMonitoring:
# Email subject text to notify tech support that a package has exceeded the limit for domain creates
packageCreateLimitEmailSubject: "ACTION REQUIRED: Package needs to be upgraded"
# Email body text template notify support that a package has exceeded the limit for domain creates
packageCreateLimitEmailBody: >
# Configuration options for the bulk pricing package compliance monitoring
bulkPricingPackageMonitoring:
# Email subject text to notify tech support that a bulk pricing package has exceeded the limit for domain creates
bulkPricingPackageCreateLimitEmailSubject: "ACTION REQUIRED: Bulk pricing package needs to be upgraded"
# Email body text template notify support that a bulk pricing package has exceeded the limit for domain creates
bulkPricingPackageCreateLimitEmailBody: >
Dear Support,
A package has exceeded its max create limit and needs to be upgraded to the
A bulk pricing package has exceeded its max create limit and needs to be upgraded to the
next tier.
Package ID: %1$s
Package Token: %2$s
Bulk Pricing ID: %1$s
Bulk Token: %2$s
Registrar: %3$s
Current Max Create Limit: %4$s
Creates Completed: %5$s
# Email subject text to notify support that a package has exceeded the limit
# Email subject text to notify support that a bulk pricing package has exceeded the limit
# for current active domains and a warning needs to be sent
packageDomainLimitWarningEmailSubject: "ACTION REQUIRED: Package has exceeded the domain limit - send warning"
# Email body text template to inform support that a package has exceeded the
# limit for active domains and a warning needs to be sent that the package
bulkPricingPackageDomainLimitWarningEmailSubject: "ACTION REQUIRED: Bulk pricing package has exceeded the domain limit - send warning"
# Email body text template to inform support that a bulk pricing package has exceeded the
# limit for active domains and a warning needs to be sent that the bulk pricing package
# will be upgraded in 30 days
packageDomainLimitWarningEmailBody: >
bulkPricingPackageDomainLimitWarningEmailBody: >
Dear Support,
A package has exceeded its max domain limit. Please send a warning to the
registrar that their package will be upgraded to the next tier in 30 days if
A bulk pricing package has exceeded its max domain limit. Please send a warning to the
registrar that their bulk pricing package will be upgraded to the next tier in 30 days if
the number of active domains does not return below the limit.
Package ID: %1$s
Package Token: %2$s
Bulk Pricing ID: %1$s
Bulk Token: %2$s
Registrar: %3$s
Active Domain Limit: %4$s
Current Active Domains: %5$s
# Email subject text to notify support that a package has exceeded the limit
# Email subject text to notify support that a bulk pricing package has exceeded the limit
# for current active domains for more than 30 days and needs to be upgraded
packageDomainLimitUpgradeEmailSubject: "ACTION REQUIRED: Package has exceeded the domain limit - upgrade package"
# Email body text template to inform support that a package has exceeded the
bulkPricingPackageDomainLimitUpgradeEmailSubject: "ACTION REQUIRED: Bulk pricing package has exceeded the domain limit - upgrade package"
# Email body text template to inform support that a bulk pricing package has exceeded the
# limit for active domains for more than 30 days and needs to be upgraded
packageDomainLimitUpgradeEmailBody: >
bulkPricingPackageDomainLimitUpgradeEmailBody: >
Dear Support,
A package has exceeded its max domain limit for over 30 days and needs to be
A bulk pricing package has exceeded its max domain limit for over 30 days and needs to be
upgraded to the next tier.
Package ID: %1$s
Package Token: %2$s
Bulk Pricing ID: %1$s
Bulk Token: %2$s
Registrar: %3$s
Active Domain Limit: %4$s
Current Active Domains: %5$s
@@ -152,7 +152,7 @@ import org.joda.time.Duration;
* @error {@link DomainCreateFlow.MustHaveSignedMarksInCurrentPhaseException}
* @error {@link DomainCreateFlow.NoGeneralRegistrationsInCurrentPhaseException}
* @error {@link DomainCreateFlow.NoTrademarkedRegistrationsBeforeSunriseException}
* @error {@link DomainCreateFlow.PackageDomainRegisteredForTooManyYearsException}
* @error {@link BulkDomainRegisteredForTooManyYearsException}
* @error {@link DomainCreateFlow.SignedMarksOnlyDuringSunriseException}
* @error {@link DomainFlowTmchUtils.NoMarksFoundMatchingDomainException}
* @error {@link DomainFlowTmchUtils.FoundMarkNotYetValidException}
@@ -405,12 +405,11 @@ public final class DomainCreateFlow implements TransactionalFlow {
: hasClaimsNotice ? LordnPhase.CLAIMS : LordnPhase.NONE);
Domain domain = domainBuilder.build();
if (allocationToken.isPresent()
&& allocationToken.get().getTokenType().equals(TokenType.PACKAGE)) {
&& allocationToken.get().getTokenType().equals(TokenType.BULK_PRICING)) {
if (years > 1) {
throw new PackageDomainRegisteredForTooManyYearsException(allocationToken.get().getToken());
throw new BulkDomainRegisteredForTooManyYearsException(allocationToken.get().getToken());
}
domain =
domain.asBuilder().setCurrentPackageToken(allocationToken.get().createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(allocationToken.get().createVKey()).build();
}
DomainHistory domainHistory =
buildDomainHistory(domain, tld, now, period, tld.getAddGracePeriodLength());
@@ -763,13 +762,12 @@ public final class DomainCreateFlow implements TransactionalFlow {
}
}
/** Package domain registered for too many years. */
static class PackageDomainRegisteredForTooManyYearsException extends CommandUseErrorException {
public PackageDomainRegisteredForTooManyYearsException(String token) {
/** Bulk pricing domain registered for too many years. */
static class BulkDomainRegisteredForTooManyYearsException extends CommandUseErrorException {
public BulkDomainRegisteredForTooManyYearsException(String token) {
super(
String.format(
"The package token %s cannot be used to register names for longer than 1 year.",
token));
"The bulk token %s cannot be used to register names for longer than 1 year.", token));
}
}
}
@@ -155,13 +155,13 @@ public final class DomainInfoFlow implements Flow {
if (!gracePeriodStatuses.isEmpty()) {
extensions.add(RgpInfoExtension.create(gracePeriodStatuses));
}
Optional<BulkTokenExtension> packageInfo =
Optional<BulkTokenExtension> bulkPricingInfo =
eppInput.getSingleExtension(BulkTokenExtension.class);
if (packageInfo.isPresent()) {
// Package info was requested.
if (bulkPricingInfo.isPresent()) {
// Bulk pricing info was requested.
if (isSuperuser || registrarId.equals(domain.getCurrentSponsorRegistrarId())) {
// Only show package info to owning registrar or superusers
extensions.add(BulkTokenResponseExtension.create(domain.getCurrentPackageToken()));
// Only show bulk pricing info to owning registrar or superusers
extensions.add(BulkTokenResponseExtension.create(domain.getCurrentBulkToken()));
}
}
Optional<FeeInfoCommandExtensionV06> feeInfo =
@@ -30,7 +30,7 @@ import static google.registry.flows.domain.DomainFlowUtils.validateFeeChallenge;
import static google.registry.flows.domain.DomainFlowUtils.validateRegistrationPeriod;
import static google.registry.flows.domain.DomainFlowUtils.verifyRegistrarIsActive;
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
import static google.registry.flows.domain.token.AllocationTokenFlowUtils.maybeApplyPackageRemovalToken;
import static google.registry.flows.domain.token.AllocationTokenFlowUtils.maybeApplyBulkPricingRemovalToken;
import static google.registry.flows.domain.token.AllocationTokenFlowUtils.verifyTokenAllowedOnDomain;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_RENEW;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -53,8 +53,8 @@ import google.registry.flows.custom.DomainRenewFlowCustomLogic.BeforeResponseRet
import google.registry.flows.custom.DomainRenewFlowCustomLogic.BeforeSaveParameters;
import google.registry.flows.custom.EntityChanges;
import google.registry.flows.domain.token.AllocationTokenFlowUtils;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemoveDomainTokenOnPackageDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemoveDomainTokenOnNonPackageDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemoveDomainTokenOnBulkPricingDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemoveDomainTokenOnNonBulkPricingDomainException;
import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingBase.Reason;
import google.registry.model.billing.BillingEvent;
@@ -121,8 +121,8 @@ import org.joda.time.Duration;
* @error {@link DomainFlowUtils.RegistrarMustBeActiveForThisOperationException}
* @error {@link DomainFlowUtils.UnsupportedFeeAttributeException}
* @error {@link DomainRenewFlow.IncorrectCurrentExpirationDateException}
* @error {@link MissingRemoveDomainTokenOnPackageDomainException}
* @error {@link RemoveDomainTokenOnNonPackageDomainException}
* @error {@link MissingRemoveDomainTokenOnBulkPricingDomainException}
* @error {@link RemoveDomainTokenOnNonBulkPricingDomainException}
* @error {@link
* google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForDomainException}
* @error {@link
@@ -194,7 +194,7 @@ public final class DomainRenewFlow implements TransactionalFlow {
verifyRenewAllowed(authInfo, existingDomain, command, allocationToken);
// If client passed an applicable static token this updates the domain
existingDomain = maybeApplyPackageRemovalToken(existingDomain, allocationToken);
existingDomain = maybeApplyBulkPricingRemovalToken(existingDomain, allocationToken);
int years = command.getPeriod().getValue();
DateTime newExpirationTime =
@@ -328,7 +328,7 @@ public final class DomainRenewFlow implements TransactionalFlow {
checkHasBillingAccount(registrarId, existingDomain.getTld());
}
verifyUnitIsYears(command.getPeriod());
// We only allow __REMOVE_PACKAGE__ token on promo package domains for now
// We only allow __REMOVE_PACKAGE__ token on bulk pricing domains for now
verifyTokenAllowedOnDomain(existingDomain, allocationToken);
// If the date they specify doesn't match the expiration, fail. (This is an idempotence check).
if (!command.getCurrentExpirationDate().equals(
@@ -154,9 +154,9 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
tm().loadByKey(existingDomain.getAutorenewBillingEvent());
HistoryEntryId domainHistoryId = createHistoryEntryId(existingDomain);
historyBuilder.setRevisionId(domainHistoryId.getRevisionId());
boolean hasPackageToken = existingDomain.getCurrentPackageToken().isPresent();
boolean hasBulkToken = existingDomain.getCurrentBulkToken().isPresent();
Money renewalPrice =
hasPackageToken ? null : existingBillingRecurrence.getRenewalPrice().orElse(null);
hasBulkToken ? null : existingBillingRecurrence.getRenewalPrice().orElse(null);
Optional<BillingEvent> billingEvent =
transferData.getTransferPeriod().getValue() == 0
? Optional.empty()
@@ -172,10 +172,10 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
Tld.get(tldStr),
targetId,
transferData.getTransferRequestTime(),
// When removing a domain from a package it should return to the
// When removing a domain from bulk pricing it should return to the
// default recurrence billing behavior so the existing recurrence
// billing event should not be passed in.
hasPackageToken ? null : existingBillingRecurrence)
hasBulkToken ? null : existingBillingRecurrence)
.getRenewCost())
.setEventTime(now)
.setBillingTime(now.plus(Tld.get(tldStr).getTransferGracePeriodLength()))
@@ -213,7 +213,7 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
.setRegistrarId(gainingRegistrarId)
.setEventTime(newExpirationTime)
.setRenewalPriceBehavior(
hasPackageToken
hasBulkToken
? RenewalPriceBehavior.DEFAULT
: existingBillingRecurrence.getRenewalPriceBehavior())
.setRenewalPrice(renewalPrice)
@@ -258,9 +258,9 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
.orElseGet(ImmutableSet::of))
.setLastEppUpdateTime(now)
.setLastEppUpdateRegistrarId(registrarId)
// Even if the existing domain had a package token, that package token should be removed
// Even if the existing domain had a bulk token, that bulk token should be removed
// on transfer
.setCurrentPackageToken(null)
.setCurrentBulkToken(null)
.build();
Tld tld = Tld.get(existingDomain.getTld());
@@ -201,11 +201,12 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
Optional<FeesAndCredits> feesAndCredits;
if (period.getValue() == 0) {
feesAndCredits = Optional.empty();
} else if (!existingDomain.getCurrentPackageToken().isPresent()) {
} else if (!existingDomain.getCurrentBulkToken().isPresent()) {
feesAndCredits =
Optional.of(pricingLogic.getTransferPrice(tld, targetId, now, existingBillingRecurrence));
} else {
// If existing domain is in a package, calculate the transfer price with default renewal price
// If existing domain is in a bulk pricing package, calculate the transfer price with default
// renewal price
// behavior
feesAndCredits =
period.getValue() == 0
@@ -146,7 +146,7 @@ public final class DomainTransferUtils {
return builder
.add(
createGainingClientAutorenewEvent(
existingDomain.getCurrentPackageToken().isPresent()
existingDomain.getCurrentBulkToken().isPresent()
? existingBillingRecurrence
.asBuilder()
.setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT)
@@ -242,19 +242,19 @@ public class AllocationTokenFlowUtils {
public static void verifyTokenAllowedOnDomain(
Domain domain, Optional<AllocationToken> allocationToken) throws EppException {
boolean domainHasPackageToken = domain.getCurrentPackageToken().isPresent();
boolean domainHasBulkToken = domain.getCurrentBulkToken().isPresent();
boolean hasRemoveDomainToken =
allocationToken.isPresent()
&& TokenBehavior.REMOVE_DOMAIN.equals(allocationToken.get().getTokenBehavior());
if (hasRemoveDomainToken && !domainHasPackageToken) {
throw new RemoveDomainTokenOnNonPackageDomainException();
} else if (!hasRemoveDomainToken && domainHasPackageToken) {
throw new MissingRemoveDomainTokenOnPackageDomainException();
if (hasRemoveDomainToken && !domainHasBulkToken) {
throw new RemoveDomainTokenOnNonBulkPricingDomainException();
} else if (!hasRemoveDomainToken && domainHasBulkToken) {
throw new MissingRemoveDomainTokenOnBulkPricingDomainException();
}
}
public static Domain maybeApplyPackageRemovalToken(
public static Domain maybeApplyBulkPricingRemovalToken(
Domain domain, Optional<AllocationToken> allocationToken) {
if (!allocationToken.isPresent()
|| !TokenBehavior.REMOVE_DOMAIN.equals(allocationToken.get().getTokenBehavior())) {
@@ -274,10 +274,10 @@ public class AllocationTokenFlowUtils {
tm().getEntityManager().flush();
tm().getEntityManager().clear();
// Remove current package token
// Remove current bulk token
return domain
.asBuilder()
.setCurrentPackageToken(null)
.setCurrentBulkToken(null)
.setAutorenewBillingEvent(newBillingRecurrence.createVKey())
.build();
}
@@ -338,19 +338,19 @@ public class AllocationTokenFlowUtils {
}
}
/** The __REMOVEDOMAIN__ token is missing on a package domain command */
public static class MissingRemoveDomainTokenOnPackageDomainException
/** The __REMOVEDOMAIN__ token is missing on a bulk pricing domain command */
public static class MissingRemoveDomainTokenOnBulkPricingDomainException
extends AssociationProhibitsOperationException {
MissingRemoveDomainTokenOnPackageDomainException() {
super("Domains that are inside packages cannot be explicitly renewed or transferred");
MissingRemoveDomainTokenOnBulkPricingDomainException() {
super("Domains that are inside bulk pricing cannot be explicitly renewed or transferred");
}
}
/** The __REMOVEDOMAIN__ token is not allowed on non package domains */
public static class RemoveDomainTokenOnNonPackageDomainException
/** The __REMOVEDOMAIN__ token is not allowed on non bulk pricing domains */
public static class RemoveDomainTokenOnNonBulkPricingDomainException
extends AssociationProhibitsOperationException {
RemoveDomainTokenOnNonPackageDomainException() {
super("__REMOVEDOMAIN__ token is not allowed on non package domains");
RemoveDomainTokenOnNonBulkPricingDomainException() {
super("__REMOVEDOMAIN__ token is not allowed on non bulk pricing domains");
}
}
}
@@ -200,7 +200,7 @@ public class Domain extends DomainBase implements ForeignKeyedEppResource {
.setStatusValues(domainBase.getStatusValues())
.setTransferData(domainBase.getTransferData())
.setLordnPhase(domainBase.getLordnPhase())
.setCurrentPackageToken(domainBase.getCurrentPackageToken().orElse(null));
.setCurrentBulkToken(domainBase.getCurrentBulkToken().orElse(null));
}
}
}
@@ -267,8 +267,12 @@ public class DomainBase extends EppResource
@Enumerated(EnumType.STRING)
LordnPhase lordnPhase = LordnPhase.NONE;
/** The {@link AllocationToken} for the package this domain is currently a part of. */
@Nullable VKey<AllocationToken> currentPackageToken;
/**
* The {@link AllocationToken} for the bulk pricing package this domain is currently a part of.
*/
@Nullable
@Column(name = "current_package_token")
VKey<AllocationToken> currentBulkToken;
public LordnPhase getLordnPhase() {
return lordnPhase;
@@ -302,8 +306,8 @@ public class DomainBase extends EppResource
return smdId;
}
public Optional<VKey<AllocationToken>> getCurrentPackageToken() {
return Optional.ofNullable(currentPackageToken);
public Optional<VKey<AllocationToken>> getCurrentBulkToken() {
return Optional.ofNullable(currentBulkToken);
}
/**
@@ -478,7 +482,7 @@ public class DomainBase extends EppResource
// events.
.setAutorenewBillingEvent(transferData.getServerApproveAutorenewEvent())
.setAutorenewPollMessage(transferData.getServerApproveAutorenewPollMessage())
.setCurrentPackageToken(null);
.setCurrentBulkToken(null);
if (transferData.getTransferPeriod().getValue() == 1) {
// Set the grace period using a key to the pre-scheduled transfer billing event. Not using
// GracePeriod.forBillingEvent() here in order to avoid the actual fetch.
@@ -910,23 +914,22 @@ public class DomainBase extends EppResource
return thisCastToDerived();
}
public B setCurrentPackageToken(@Nullable VKey<AllocationToken> currentPackageToken) {
if (currentPackageToken == null) {
getInstance().currentPackageToken = currentPackageToken;
public B setCurrentBulkToken(@Nullable VKey<AllocationToken> currentBulkToken) {
if (currentBulkToken == null) {
getInstance().currentBulkToken = currentBulkToken;
return thisCastToDerived();
}
AllocationToken token =
tm().transact(() -> tm().loadByKeyIfPresent(currentPackageToken))
tm().transact(() -> tm().loadByKeyIfPresent(currentBulkToken))
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"The package token %s does not exist",
currentPackageToken.getKey())));
"The bulk token %s does not exist", currentBulkToken.getKey())));
checkArgument(
token.getTokenType().equals(TokenType.PACKAGE),
"The currentPackageToken must have a PACKAGE TokenType");
getInstance().currentPackageToken = currentPackageToken;
token.getTokenType().equals(TokenType.BULK_PRICING),
"The currentBulkToken must have a BULK_PRICING TokenType");
getInstance().currentBulkToken = currentBulkToken;
return thisCastToDerived();
}
}
@@ -119,9 +119,14 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
/** Type of the token that indicates how and where it should be used. */
public enum TokenType {
/** Token used for bulk pricing */
BULK_PRICING,
/** Token saved on a TLD to use if no other token is passed from the client */
DEFAULT_PROMO,
/** Token used for package pricing */
/** This is the old name for what is now BULK_PRICING. */
// TODO(sarahbot@): Remove this type once all tokens of this type have been scrubbed from the
// database
@Deprecated
PACKAGE,
/** Invalid after use */
SINGLE_USE,
@@ -137,8 +142,8 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
/** No special behavior */
DEFAULT,
/**
* REMOVE_DOMAIN triggers domain removal from promotional bulk (package) pricing, bypasses
* DEFAULT token validations.
* REMOVE_DOMAIN triggers domain removal from a bulk pricing package, bypasses DEFAULT token
* validations.
*/
REMOVE_DOMAIN
}
@@ -344,12 +349,13 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
checkArgumentNotNull(getInstance().tokenType, "Token type must be specified");
checkArgument(!Strings.isNullOrEmpty(getInstance().token), "Token must not be null or empty");
checkArgument(
!getInstance().tokenType.equals(TokenType.PACKAGE)
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED),
"Package tokens must have renewalPriceBehavior set to SPECIFIED");
"Bulk tokens must have renewalPriceBehavior set to SPECIFIED");
checkArgument(
!getInstance().tokenType.equals(TokenType.PACKAGE) || !getInstance().discountPremiums,
"Package tokens cannot discount premium names");
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| !getInstance().discountPremiums,
"Bulk tokens cannot discount premium names");
checkArgument(
getInstance().domainName == null || TokenType.SINGLE_USE.equals(getInstance().tokenType),
"Domain name can only be specified for SINGLE_USE tokens");
@@ -358,10 +364,10 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
|| TokenType.SINGLE_USE.equals(getInstance().tokenType),
"Redemption history entry can only be specified for SINGLE_USE tokens");
checkArgument(
getInstance().tokenType != TokenType.PACKAGE
getInstance().tokenType != TokenType.BULK_PRICING
|| (getInstance().allowedClientIds != null
&& getInstance().allowedClientIds.size() == 1),
"PACKAGE tokens must have exactly one allowed client registrar");
"BULK_PRICING tokens must have exactly one allowed client registrar");
checkArgument(
getInstance().discountFraction > 0 || !getInstance().discountPremiums,
"Discount premiums can only be specified along with a discount fraction");
@@ -36,46 +36,53 @@ import org.hibernate.annotations.Type;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** An entity representing a package promotion. */
@Entity
/**
* An entity representing a bulk pricing promotion. Note that this table is still called
* PackagePromotion in Cloud SQL.
*/
@Entity(name = "PackagePromotion")
@javax.persistence.Table(indexes = {@javax.persistence.Index(columnList = "token")})
public class PackagePromotion extends ImmutableObject implements Buildable {
public class BulkPricingPackage extends ImmutableObject implements Buildable {
/** An autogenerated identifier for the package promotion. */
/** An autogenerated identifier for the bulk pricing promotion. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
long packagePromotionId;
@Column(name = "package_promotion_id")
long bulkPricingId;
/** The allocation token string for the package. */
/** The allocation token string for the bulk pricing package. */
@Column(nullable = false)
VKey<AllocationToken> token;
/** The maximum number of active domains the package allows at any given time. */
/** The maximum number of active domains the bulk pricing package allows at any given time. */
@Column(nullable = false)
int maxDomains;
/** The maximum number of domains that can be created in the package each year. */
/** The maximum number of domains that can be created in the bulk pricing package each year. */
@Column(nullable = false)
int maxCreates;
/** The annual price of the package. */
/** The annual price of the bulk pricing package. */
@Type(type = JodaMoneyType.TYPE_NAME)
@Columns(
columns = {
@Column(name = "package_price_amount", nullable = false),
@Column(name = "package_price_currency", nullable = false)
})
Money packagePrice;
Money bulkPrice;
/** The next billing date of the package. */
/** The next billing date of the bulk pricing package. */
@Column(nullable = false)
DateTime nextBillingDate = END_OF_TIME;
/** Date the last warning email was sent that the package has exceeded the maxDomains limit. */
/**
* Date the last warning email was sent that the bulk pricing package has exceeded the maxDomains
* limit.
*/
@Nullable DateTime lastNotificationSent;
public long getId() {
return packagePromotionId;
return bulkPricingId;
}
public VKey<AllocationToken> getToken() {
@@ -90,8 +97,8 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return maxCreates;
}
public Money getPackagePrice() {
return packagePrice;
public Money getBulkPrice() {
return bulkPrice;
}
public DateTime getNextBillingDate() {
@@ -102,18 +109,18 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return Optional.ofNullable(lastNotificationSent);
}
/** Loads and returns a PackagePromotion entity by its token string directly from Cloud SQL. */
public static Optional<PackagePromotion> loadByTokenString(String tokenString) {
/** Loads and returns a BulkPricingPackage entity by its token string directly from Cloud SQL. */
public static Optional<BulkPricingPackage> loadByTokenString(String tokenString) {
tm().assertInTransaction();
return tm().query("FROM PackagePromotion WHERE token = :token", PackagePromotion.class)
return tm().query("FROM PackagePromotion WHERE token = :token", BulkPricingPackage.class)
.setParameter("token", VKey.create(AllocationToken.class, tokenString))
.getResultStream()
.findFirst();
}
@Override
public VKey<PackagePromotion> createVKey() {
return VKey.create(PackagePromotion.class, packagePromotionId);
public VKey<BulkPricingPackage> createVKey() {
return VKey.create(BulkPricingPackage.class, bulkPricingId);
}
@Override
@@ -121,28 +128,29 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return new Builder(clone(this));
}
/** A builder for constructing {@link PackagePromotion} objects, since they are immutable. */
public static class Builder extends Buildable.Builder<PackagePromotion> {
/** A builder for constructing {@link BulkPricingPackage} objects, since they are immutable. */
public static class Builder extends Buildable.Builder<BulkPricingPackage> {
public Builder() {}
private Builder(PackagePromotion instance) {
private Builder(BulkPricingPackage instance) {
super(instance);
}
@Override
public PackagePromotion build() {
public BulkPricingPackage build() {
checkArgumentNotNull(getInstance().token, "Allocation token must be specified");
AllocationToken allocationToken = tm().transact(() -> tm().loadByKey(getInstance().token));
checkArgument(
allocationToken.tokenType == TokenType.PACKAGE,
"Allocation token must be a PACKAGE type");
allocationToken.tokenType == TokenType.BULK_PRICING,
"Allocation token must be a BULK_PRICING type");
return super.build();
}
public Builder setToken(AllocationToken token) {
checkArgumentNotNull(token, "Allocation token must not be null");
checkArgument(
token.tokenType == TokenType.PACKAGE, "Allocation token must be a PACKAGE type");
token.tokenType == TokenType.BULK_PRICING,
"Allocation token must be a BULK_PRICING type");
getInstance().token = token.createVKey();
return this;
}
@@ -159,9 +167,9 @@ public class PackagePromotion extends ImmutableObject implements Buildable {
return this;
}
public Builder setPackagePrice(Money packagePrice) {
checkArgumentNotNull(packagePrice, "Package price must not be null");
getInstance().packagePrice = packagePrice;
public Builder setBulkPrice(Money bulkPrice) {
checkArgumentNotNull(bulkPrice, "Bulk price must not be null");
getInstance().bulkPrice = bulkPrice;
return this;
}
@@ -16,23 +16,23 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import org.jetbrains.annotations.Nullable;
/** Command to create a PackagePromotion */
/** Command to create a {@link BulkPricingPackage} */
@Parameters(
separators = " =",
commandDescription =
"Create new package promotion object(s) for registrars to register multiple names under"
+ " one contractual annual package price using a package allocation token")
public final class CreatePackagePromotionCommand extends CreateOrUpdatePackagePromotionCommand {
"Create new bulk pricing package object(s) for registrars to register multiple names under"
+ " one contractual annual bulk price using a bulk pricing allocation token")
public final class CreateBulkPricingPackageCommand extends CreateOrUpdateBulkPricingPackageCommand {
@Nullable
@Override
PackagePromotion getOldPackagePromotion(String tokenString) {
BulkPricingPackage getOldBulkPricingPackage(String tokenString) {
checkArgument(
!PackagePromotion.loadByTokenString(tokenString).isPresent(),
"PackagePromotion with token %s already exists",
!BulkPricingPackage.loadByTokenString(tokenString).isPresent(),
"BulkPricingPackage with token %s already exists",
tokenString);
return null;
}
@@ -20,7 +20,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import com.beust.jcommander.Parameter;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import google.registry.persistence.VKey;
import java.util.Date;
import java.util.List;
@@ -29,39 +29,40 @@ import javax.annotation.Nullable;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** Shared base class for commands to create or update a PackagePromotion object. */
abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
/** Shared base class for commands to create or update a {@link BulkPricingPackage} object. */
abstract class CreateOrUpdateBulkPricingPackageCommand extends MutatingCommand {
@Parameter(description = "Allocation token String of the package token", required = true)
@Parameter(description = "Allocation token String of the bulk token", required = true)
List<String> mainParameters;
@Nullable
@Parameter(
names = {"-d", "--max_domains"},
description = "Maximum concurrent active domains allowed in the package")
description = "Maximum concurrent active domains allowed in the bulk pricing package")
Integer maxDomains;
@Nullable
@Parameter(
names = {"-c", "--max_creates"},
description = "Maximum domain creations allowed in the package each year")
description = "Maximum domain creations allowed in the bulk pricing package each year")
Integer maxCreates;
@Nullable
@Parameter(
names = {"-p", "--price"},
description = "Annual price of the package")
description = "Annual price of the bulk pricing package")
Money price;
@Nullable
@Parameter(
names = "--next_billing_date",
description = "The next date that the package should be billed for its annual fee")
description =
"The next date that the bulk pricing package should be billed for its annual fee")
Date nextBillingDate;
/** Returns the existing PackagePromotion or null if it does not exist. */
/** Returns the existing BulkPricingPackage or null if it does not exist. */
@Nullable
abstract PackagePromotion getOldPackagePromotion(String token);
abstract BulkPricingPackage getOldBulkPricingPackage(String token);
/** Returns the allocation token object. */
AllocationToken getAndCheckAllocationToken(String token) {
@@ -69,12 +70,12 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token)));
checkArgument(
allocationToken.isPresent(),
"An allocation token with the token String %s does not exist. The package token must be"
+ " created first before it can be used to create a PackagePromotion",
"An allocation token with the token String %s does not exist. The bulk token must be"
+ " created first before it can be used to create a BulkPricingPackage",
token);
checkArgument(
allocationToken.get().getTokenType().equals(TokenType.PACKAGE),
"The allocation token must be of the PACKAGE token type");
allocationToken.get().getTokenType().equals(TokenType.BULK_PRICING),
"The allocation token must be of the BULK_PRICING token type");
return allocationToken.get();
}
@@ -88,21 +89,21 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
for (String token : mainParameters) {
tm().transact(
() -> {
PackagePromotion oldPackage = getOldPackagePromotion(token);
BulkPricingPackage oldBulkPricingPackage = getOldBulkPricingPackage(token);
checkArgument(
oldPackage != null || price != null,
"PackagePrice is required when creating a new package");
oldBulkPricingPackage != null || price != null,
"BulkPrice is required when creating a new bulk pricing package");
AllocationToken allocationToken = getAndCheckAllocationToken(token);
PackagePromotion.Builder builder =
(oldPackage == null)
? new PackagePromotion.Builder().setToken(allocationToken)
: oldPackage.asBuilder();
BulkPricingPackage.Builder builder =
(oldBulkPricingPackage == null)
? new BulkPricingPackage.Builder().setToken(allocationToken)
: oldBulkPricingPackage.asBuilder();
Optional.ofNullable(maxDomains).ifPresent(builder::setMaxDomains);
Optional.ofNullable(maxCreates).ifPresent(builder::setMaxCreates);
Optional.ofNullable(price).ifPresent(builder::setPackagePrice);
Optional.ofNullable(price).ifPresent(builder::setBulkPrice);
Optional.ofNullable(nextBillingDate)
.ifPresent(
nextBillingDate ->
@@ -110,8 +111,8 @@ abstract class CreateOrUpdatePackagePromotionCommand extends MutatingCommand {
if (clearLastNotificationSent()) {
builder.setLastNotificationSent(null);
}
PackagePromotion newPackage = builder.build();
stageEntityChange(oldPackage, newPackage);
BulkPricingPackage newBUlkPricingPackage = builder.build();
stageEntityChange(oldBulkPricingPackage, newBUlkPricingPackage);
});
}
}
@@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.DEFAULT;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -279,19 +279,20 @@ class GenerateAllocationTokensCommand implements Command {
}
if (!isNullOrEmpty(tokenStatusTransitions)) {
// Don't allow package tokens to be created with a scheduled end time since this could allow
// future domains to be attributed to the package and never be billed. Package promotion
// Don't allow bulk tokens to be created with a scheduled end time since this could allow
// future domains to be attributed to the bulk pricing package and never be billed. Bulk
// tokens should only be scheduled to end with a brief time period before the status
// transition occurs so that no new domains are registered using that token between when the
// status is scheduled and when the transition occurs.
// TODO(@sarahbot): Create a cleaner way to handle ending packages once we actually have
// customers using them
// TODO(@sarahbot): Create a cleaner way to handle ending bulk pricing packages once we
// actually have customers using them
boolean hasEnding =
tokenStatusTransitions.containsValue(TokenStatus.ENDED)
|| tokenStatusTransitions.containsValue(TokenStatus.CANCELLED);
checkArgument(
!(PACKAGE.equals(tokenType) && hasEnding),
"PACKAGE tokens should not be generated with ENDED or CANCELLED in their transition map");
!(BULK_PRICING.equals(tokenType) && hasEnding),
"BULK_PRICING tokens should not be generated with ENDED or CANCELLED in their transition"
+ " map");
}
if (tokenStrings != null) {
@@ -19,14 +19,14 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.List;
/** Command to show a {@link PackagePromotion} object. */
@Parameters(separators = " =", commandDescription = "Show package promotion object(s)")
public class GetPackagePromotionCommand extends GetEppResourceCommand {
/** Command to show a {@link BulkPricingPackage} object. */
@Parameters(separators = " =", commandDescription = "Show bulk pricing package object(s)")
public class GetBulkPricingPackageCommand extends GetEppResourceCommand {
@Parameter(description = "Package token(s)", required = true)
@Parameter(description = "Bulk pricing token(s)", required = true)
private List<String> mainParameters;
@Override
@@ -34,12 +34,12 @@ public class GetPackagePromotionCommand extends GetEppResourceCommand {
for (String token : mainParameters) {
tm().transact(
() -> {
PackagePromotion packagePromotion =
BulkPricingPackage bulkPricingPackage =
checkArgumentPresent(
PackagePromotion.loadByTokenString(token),
"PackagePromotion with package token %s does not exist",
BulkPricingPackage.loadByTokenString(token),
"BulkPricingPackage with token %s does not exist",
token);
System.out.println(packagePromotion);
System.out.println(bulkPricingPackage);
});
}
}
@@ -36,6 +36,7 @@ public final class RegistryTool {
.put("convert_idn", ConvertIdnCommand.class)
.put("count_domains", CountDomainsCommand.class)
.put("create_anchor_tenant", CreateAnchorTenantCommand.class)
.put("create_bulk_pricing_package", CreateBulkPricingPackageCommand.class)
.put(
"create_cancellations_for_billing_events",
CreateCancellationsForBillingEventsCommand.class)
@@ -43,7 +44,6 @@ public final class RegistryTool {
.put("create_contact", CreateContactCommand.class)
.put("create_domain", CreateDomainCommand.class)
.put("create_host", CreateHostCommand.class)
.put("create_package_promotion", CreatePackagePromotionCommand.class)
.put("create_premium_list", CreatePremiumListCommand.class)
.put("create_registrar", CreateRegistrarCommand.class)
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
@@ -67,13 +67,13 @@ public final class RegistryTool {
.put("generate_lordn", GenerateLordnCommand.class)
.put("generate_zone_files", GenerateZoneFilesCommand.class)
.put("get_allocation_token", GetAllocationTokenCommand.class)
.put("get_bulk_pricing_package", GetBulkPricingPackageCommand.class)
.put("get_claims_list", GetClaimsListCommand.class)
.put("get_contact", GetContactCommand.class)
.put("get_domain", GetDomainCommand.class)
.put("get_history_entries", GetHistoryEntriesCommand.class)
.put("get_host", GetHostCommand.class)
.put("get_keyring_secret", GetKeyringSecretCommand.class)
.put("get_package_promotion", GetPackagePromotionCommand.class)
.put("get_premium_list", GetPremiumListCommand.class)
.put("get_registrar", GetRegistrarCommand.class)
.put("get_reserved_list", GetReservedListCommand.class)
@@ -104,10 +104,10 @@ public final class RegistryTool {
.put("unlock_domain", UnlockDomainCommand.class)
.put("unrenew_domain", UnrenewDomainCommand.class)
.put("update_allocation_tokens", UpdateAllocationTokensCommand.class)
.put("update_bulk_pricing_package", UpdateBulkPricingPackageCommand.class)
.put("update_cursors", UpdateCursorsCommand.class)
.put("update_domain", UpdateDomainCommand.class)
.put("update_keyring_secret", UpdateKeyringSecretCommand.class)
.put("update_package_promotion", UpdatePackagePromotionCommand.class)
.put("update_premium_list", UpdatePremiumListCommand.class)
.put("update_recurrence", UpdateRecurrenceCommand.class)
.put("update_registrar", UpdateRegistrarCommand.class)
@@ -120,7 +120,7 @@ interface RegistryToolComponent {
void inject(GetHostCommand command);
void inject(GetPackagePromotionCommand command);
void inject(GetBulkPricingPackageCommand command);
void inject(GetKeyringSecretCommand command);
@@ -169,18 +169,18 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
}
private AllocationToken updateToken(AllocationToken original) {
if (endToken && original.getTokenType().equals(TokenType.PACKAGE)) {
Long domainsInPackage =
tm().query("SELECT COUNT(*) FROM Domain WHERE currentPackageToken = :token", Long.class)
if (endToken && original.getTokenType().equals(TokenType.BULK_PRICING)) {
Long domainsInBulkPackage =
tm().query("SELECT COUNT(*) FROM Domain WHERE currentBulkToken = :token", Long.class)
.setParameter("token", original.createVKey())
.getSingleResult();
checkArgument(
domainsInPackage == 0,
"Package token %s can not end its promotion because it still has %s domains in the"
+ " package",
domainsInBulkPackage == 0,
"Bulk token %s can not end its promotion because it still has %s domains in the"
+ " promotion",
original.getToken(),
domainsInPackage);
domainsInBulkPackage);
}
AllocationToken.Builder builder = original.asBuilder();
Optional.ofNullable(allowedClientIds)
@@ -17,12 +17,12 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.Optional;
/** Command to update a PackagePromotion */
@Parameters(separators = " =", commandDescription = "Update package promotion object(s)")
public final class UpdatePackagePromotionCommand extends CreateOrUpdatePackagePromotionCommand {
/** Command to update a {@link BulkPricingPackage} */
@Parameters(separators = " =", commandDescription = "Update bulk pricing package object(s)")
public final class UpdateBulkPricingPackageCommand extends CreateOrUpdateBulkPricingPackageCommand {
@Parameter(
names = "--clear_last_notification_sent",
@@ -32,10 +32,14 @@ public final class UpdatePackagePromotionCommand extends CreateOrUpdatePackagePr
boolean clearLastNotificationSent;
@Override
PackagePromotion getOldPackagePromotion(String token) {
Optional<PackagePromotion> oldPackage = PackagePromotion.loadByTokenString(token);
checkArgument(oldPackage.isPresent(), "PackagePromotion with token %s does not exist", token);
return oldPackage.get();
BulkPricingPackage getOldBulkPricingPackage(String token) {
Optional<BulkPricingPackage> oldBulkPricingPackage =
BulkPricingPackage.loadByTokenString(token);
checkArgument(
oldBulkPricingPackage.isPresent(),
"BulkPricingPackage with token %s does not exist",
token);
return oldBulkPricingPackage.get();
}
@Override
@@ -53,7 +53,7 @@
<class>google.registry.model.domain.secdns.DomainDsData</class>
<class>google.registry.model.domain.secdns.DomainDsDataHistory</class>
<class>google.registry.model.domain.token.AllocationToken</class>
<class>google.registry.model.domain.token.PackagePromotion</class>
<class>google.registry.model.domain.token.BulkPricingPackage</class>
<class>google.registry.model.host.HostHistory</class>
<class>google.registry.model.host.Host</class>
<class>google.registry.model.poll.PollMessage</class>