public void validateExperimentBuckets(List<Bucket> buckets) { if ((buckets == null) || (buckets.isEmpty())) { throw new IllegalArgumentException("No experiment buckets specified"); } Double totalAllocation = 0.0; Integer numControl = 0; Integer nOpen = 0; for (Bucket bucket : buckets) { Double val = bucket.getAllocationPercent(); totalAllocation += val; if (bucket.getState() == Bucket.State.OPEN || bucket.getState() == null) { nOpen++; } if (bucket.isControl()) { numControl++; } } if ((nOpen > 0 && Math.abs(totalAllocation - 1.0) > 1e-12) || (nOpen == 0 && Double.doubleToRawLongBits(totalAllocation) != 0)) { throw new IllegalArgumentException("Total allocation must be 1.0 (or 0.0 if all buckets are closed/empty"); } if (numControl > 1) { throw new IllegalArgumentException("Only one bucket may be specified as a control bucket"); } }
private Builder(Bucket other) { instance = new Bucket(); instance.experimentID = other.getExperimentID(); instance.label = other.getLabel(); instance.control = other.isControl() == null ? Boolean.FALSE : other.isControl(); instance.allocationPercent = other.getAllocationPercent(); instance.description = other.getDescription(); instance.payload = other.getPayload(); instance.state = other.getState(); }
public Bucket build() { Bucket result = new Bucket(); result.setControl(instance.isControl()); result.setState(instance.getState()); result.setLabel(instance.getLabel()); result.setPayload(instance.getPayload()); result.setAllocationPercent(instance.getAllocationPercent()); result.setDescription(instance.getDescription()); result.setExperimentID(instance.getExperimentID()); instance = null; return result; } }
public void validateExperimentBuckets(List<Bucket> buckets) { if ((buckets == null) || (buckets.isEmpty())) { throw new IllegalArgumentException("No experiment buckets specified"); } Double totalAllocation = 0.0; Integer numControl = 0; Integer nOpen = 0; for (Bucket bucket : buckets) { Double val = bucket.getAllocationPercent(); totalAllocation += val; if (bucket.getState() == Bucket.State.OPEN || bucket.getState() == null) { nOpen++; } if (bucket.isControl()) { numControl++; } } if ((nOpen > 0 && Math.abs(totalAllocation - 1.0) > 1e-12) || (nOpen == 0 && Double.doubleToRawLongBits(totalAllocation) != 0)) { throw new IllegalArgumentException("Total allocation must be 1.0 (or 0.0 if all buckets are closed/empty"); } if (numControl > 1) { throw new IllegalArgumentException("Only one bucket may be specified as a control bucket"); } }
/** * This method takes a list of buckets and transforms it to the {@link BucketDetail}s that are needed * for later extension. * * @param buckets a list of {@link Bucket}s */ public void addBuckets(List<Bucket> buckets) { List<BucketDetail> details = buckets.stream() .map(b -> new BucketDetail(b.getLabel(), b.isControl(), b.getAllocationPercent(), b.getState(), b.getDescription())) .collect(Collectors.toList()); setBuckets(details); }
private void checkBucketConstraint(Experiment experiment, Bucket newBucket) { Bucket test = cassandraRepository.getBucket(newBucket.getExperimentID(), newBucket.getLabel()); if (test != null) { throw new ConstraintViolationException(ConstraintViolationException.Reason.UNIQUE_CONSTRAINT_VIOLATION, "Bucket label must be unique within an experiment", null); } if (!experiment.getState().equals(Experiment.State.DRAFT) && newBucket.isControl() != null && newBucket.isControl()) { throw new ConstraintViolationException(ConstraintViolationException.Reason.APPLICATION_CONSTRAINT_VIOLATION, "Bucket added to a running experiment may not be a control bucket", null); } }
private Builder(Bucket other) { instance = new Bucket(); instance.experimentID = other.getExperimentID(); instance.label = other.getLabel(); instance.control = other.isControl() == null ? Boolean.FALSE : other.isControl(); instance.allocationPercent = other.getAllocationPercent(); instance.description = other.getDescription(); instance.payload = other.getPayload(); instance.state = other.getState(); }
Bucket.BucketAuditInfo changeData; if (updates.isControl() != null && !updates.isControl().equals(bucket.isControl())) { builder.withControl(updates.isControl()); changeData = new Bucket.BucketAuditInfo("is_control", bucket.isControl().toString(), updates.isControl().toString()); changeList.add(changeData);
if (bucketList.getBuckets().get(i).isControl() != null) { hasval = true; break; for (int i = 0; i < bucketListSize; i++) { Bucket b = bucketList.getBuckets().get(i); if (b.isControl() != null) { SQL.append("WHEN ? then ? "); if (b.isControl() != null) { args.add(b.getLabel().toString()); args.add(b.isControl().toString());
/** * {@inheritDoc} */ @Override public void createBucket(Bucket newBucket) { LOGGER.debug("Creating bucket {}", newBucket); Preconditions.checkNotNull(newBucket, "Parameter \"newBucket\" cannot be null"); final Bucket.State STATE = Bucket.State.OPEN; try { bucketAccessor.insert(newBucket.getExperimentID().getRawID(), newBucket.getLabel().toString(), newBucket.getDescription(), newBucket.getAllocationPercent(), newBucket.isControl(), newBucket.getPayload(), STATE.name()); } catch (Exception e) { LOGGER.error("Error creating bucket {}", newBucket, e); throw new RepositoryException("Could not create bucket \"" + newBucket + "\" because " + e, e); } }
@Override public void createBucket(Bucket newBucket) throws RepositoryException { final String SQL = "insert into bucket (" + "experiment_id, description, label, allocation_percent, is_control, payload, state) " + "values (?,?,?,?,?,?,?)"; try { newTransaction().insert( SQL, newBucket.getExperimentID(), newBucket.getDescription() != null ? newBucket.getDescription() : "", newBucket.getLabel().toString(), newBucket.getAllocationPercent(), newBucket.isControl() != null ? newBucket.isControl() : false, newBucket.getPayload() != null ? newBucket.getPayload() : "", Bucket.State.OPEN.toString()); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException("Could not create bucket \"" + newBucket + "\"", e); } }
public Bucket build() { Bucket result = new Bucket(); result.setControl(instance.isControl()); result.setState(instance.getState()); result.setLabel(instance.getLabel()); result.setPayload(instance.getPayload()); result.setAllocationPercent(instance.getAllocationPercent()); result.setDescription(instance.getDescription()); result.setExperimentID(instance.getExperimentID()); instance = null; return result; } }
builder.withAllocationPercent(newPct); builder.withState(newState); builder.withControl(buck.isControl()); builder.withDescription(buck.getDescription()); newBuckets.addBucket(builder.build());
Bucket newBucket = Bucket.newInstance(experimentID, bucketLabel) .withAllocationPercent(bucket.getAllocationPercent()) .withControl(bucket.isControl()) .withDescription(bucket.getDescription()) .withPayload(bucket.getPayload())