Read from bloom filter for premium pricing checks

This also cleans up the PremiumList API so that it only has one
method for checking premium prices, which is by TLD, rather than two.

I will be refactoring a lot of the static methods currently residing in
the PremiumList class into a separate utils class, but I don't want to
include too many changes in this one CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148475345
This commit is contained in:
mcilwain 2017-02-24 10:32:23 -08:00 committed by Ben McIlwain
parent 3ac74fa449
commit 3ca9bb6aeb
18 changed files with 328 additions and 282 deletions

View file

@ -75,11 +75,8 @@ abstract class CreateOrUpdatePremiumListCommand extends ConfirmingCommand
protected void init() throws Exception {
name = isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
List<String> lines = Files.readAllLines(inputFile, UTF_8);
// Try constructing the premium list locally to check up front for validation errors.
new PremiumList.Builder()
.setName(name)
.setPremiumListMapFromLines(lines)
.build();
// Try constructing and parsing the premium list locally to check up front for validation errors
new PremiumList.Builder().setName(name).build().parse(lines);
inputLineCount = lines.size();
}
@ -108,7 +105,7 @@ abstract class CreateOrUpdatePremiumListCommand extends ConfirmingCommand
getCommandPath(),
params.build(),
MediaType.FORM_DATA,
requestBody.getBytes());
requestBody.getBytes(UTF_8));
return extractServerResponse(response);
}

View file

@ -62,9 +62,6 @@ final class DeletePremiumListCommand extends ConfirmingCommand implements Remote
@Override
protected String execute() throws Exception {
premiumList.delete();
return String.format(
"Deleted premium list %s with %d entries.\n",
premiumList.getName(),
premiumList.getPremiumListEntries().size());
return String.format("Deleted premium list '%s'.\n", premiumList.getName());
}
}

View file

@ -16,6 +16,7 @@ package google.registry.tools.server;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.registry.Registries.assertTldExists;
import static google.registry.model.registry.label.PremiumList.saveWithEntries;
import static google.registry.request.Action.Method.POST;
import com.google.common.base.Splitter;
@ -52,16 +53,14 @@ public class CreatePremiumListAction extends CreateOrUpdatePremiumListAction {
logger.infofmt("Got the following input data: %s", inputData);
List<String> inputDataPreProcessed =
Splitter.on('\n').omitEmptyStrings().splitToList(inputData);
PremiumList premiumList = new PremiumList.Builder()
.setName(name)
.setPremiumListMapFromLines(inputDataPreProcessed)
.build();
premiumList.saveAndUpdateEntries();
PremiumList premiumList = new PremiumList.Builder().setName(name).build();
saveWithEntries(premiumList, inputDataPreProcessed);
logger.infofmt("Saved premium list %s with entries %s",
premiumList.getName(),
premiumList.getPremiumListEntries());
response.setPayload(ImmutableMap.of("status", "success"));
String message =
String.format(
"Saved premium list %s with %d entries",
premiumList.getName(), inputDataPreProcessed.size());
logger.info(message);
response.setPayload(ImmutableMap.of("status", "success", "message", message));
}
}

View file

@ -15,6 +15,7 @@
package google.registry.tools.server;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.registry.label.PremiumList.saveWithEntries;
import static google.registry.request.Action.Method.POST;
import com.google.common.base.Optional;
@ -38,9 +39,9 @@ public class UpdatePremiumListAction extends CreateOrUpdatePremiumListAction {
@Override
protected void savePremiumList() {
Optional<PremiumList> existingName = PremiumList.get(name);
Optional<PremiumList> existingPremiumList = PremiumList.get(name);
checkArgument(
existingName.isPresent(),
existingPremiumList.isPresent(),
"Could not update premium list %s because it doesn't exist.",
name);
@ -48,21 +49,13 @@ public class UpdatePremiumListAction extends CreateOrUpdatePremiumListAction {
logger.infofmt("Got the following input data: %s", inputData);
List<String> inputDataPreProcessed =
Splitter.on('\n').omitEmptyStrings().splitToList(inputData);
PremiumList premiumList = existingName.get().asBuilder()
.setPremiumListMapFromLines(inputDataPreProcessed)
.build();
premiumList.saveAndUpdateEntries();
PremiumList newPremiumList = saveWithEntries(existingPremiumList.get(), inputDataPreProcessed);
logger.infofmt("Updated premium list %s with entries %s",
premiumList.getName(),
premiumList.getPremiumListEntries());
String message = String.format(
"Saved premium list %s with %d entries.\n",
premiumList.getName(),
premiumList.getPremiumListEntries().size());
response.setPayload(ImmutableMap.of(
"status", "success",
"message", message));
String message =
String.format(
"Updated premium list %s with %d entries.",
newPremiumList.getName(), inputDataPreProcessed.size());
logger.info(message);
response.setPayload(ImmutableMap.of("status", "success", "message", message));
}
}