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; } }
/** * {@inheritDoc} */ @Override public void validateBucketChanges(Bucket bucket, Bucket updates) { if (updates.getExperimentID() != null && !updates.getExperimentID().equals(bucket.getExperimentID())) { throw new IllegalArgumentException("Invalid value for experimentID \"" + updates.getExperimentID() + " \"." + " Cannot update ExperimentID"); } if (updates.getLabel() != null && !updates.getLabel().equals(bucket.getLabel())) { throw new IllegalArgumentException("Invalid value for bucket label \"" + updates.getLabel() + " \". " + "Cannot update bucket label"); } if (updates.getState() != null && !updates.getState().equals(bucket.getState())) { throw new IllegalArgumentException("Cannot update the state of a bucket using this api"); } }
/** * {@inheritDoc} */ @Override public Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage) { try { bucketAccessor.updateAllocation(desiredAllocationPercentage, bucket.getExperimentID().getRawID(), bucket.getLabel().toString()); } catch (Exception e) { throw new RepositoryException("Could not update bucket allocation percentage \"" + bucket.getExperimentID() + "\".\"" + bucket.getLabel() + "\"", e); } // return the bucket with the updated values bucket = getBucket(bucket.getExperimentID(), bucket.getLabel()); return bucket; }
/** * @param bucket bucket to update * @param desiredAllocationPercentage allocation information * @return bucket that were passed in???? * @throws RepositoryException */ @Override public Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage) throws RepositoryException { final String SQL = "update bucket " + "set allocation_percent=? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, desiredAllocationPercentage.toString(), bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; }
@Override public Bucket updateBucketState(Bucket bucket, Bucket.State desiredState) throws RepositoryException { final String SQL = "update bucket " + "set state = ? " + "where experiment_id=? and label=?"; newTransaction().update( SQL, desiredState.toString(), bucket.getExperimentID(), bucket.getLabel().toString()); return bucket; }
/** * {@inheritDoc} */ @Override public Bucket updateBucketState(Bucket bucket, Bucket.State desiredState) { LOGGER.debug("Updating bucket {} state {}", new Object[]{bucket, desiredState}); try { bucketAccessor.updateState(desiredState.name(), bucket .getExperimentID().getRawID(), bucket.getLabel().toString()); Result<com.intuit.wasabi.repository.cassandra.pojo.Bucket> bucketPojo = bucketAccessor.getBucketByExperimentIdAndBucket(bucket.getExperimentID() .getRawID(), bucket.getLabel().toString()); return BucketHelper.makeBucket(bucketPojo.one()); } catch (Exception e) { LOGGER.error("Error while updating bucket {} state {}", new Object[]{bucket, desiredState}, e); throw new RepositoryException("Exception while updating bucket state " + bucket + " state " + desiredState, e); } }
Preconditions.checkNotNull(bucket.getExperimentID(), "Bucket experiment ID cannot be null"); Preconditions.checkArgument( newTransaction().update( SQL, bucket.getExperimentID()); ? bucket.getPayload() : "", bucket.getExperimentID(), bucket.getLabel().toString());
List<Bucket> buckets = bucketAccessor.getBucketByExperimentId(bucket.getExperimentID() .getRawID()).all().stream().map(BucketHelper::makeBucket) .collect(Collectors.toList()); currentBucket.getExperimentID().getRawID(), currentBucket.getLabel().toString())); bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "", bucket.getExperimentID().getRawID(), bucket.getLabel().toString()); throw new RepositoryException("Could not update bucket \"" + bucket.getExperimentID() + "\".\"" + bucket.getLabel() + "\"", e);
/** * {@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); } }
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(); }
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); } }
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; } }
/** * {@inheritDoc} */ @Override public Bucket createBucket(Experiment.ID experimentID, Bucket newBucket, UserInfo user) { Experiment experiment = experiments.getExperiment(experimentID); if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } validateExperimentState(experiment); checkBucketConstraint(experiment, newBucket); LOGGER.debug("Add Bucket: adding new bucket to running experiment" + experiment.getID()); cassandraRepository.createBucket(newBucket); try { databaseRepository.createBucket(newBucket); } catch (RepositoryException e) { cassandraRepository.deleteBucket(newBucket.getExperimentID(), newBucket.getLabel()); throw e; } //if we just created an experiment in a running experiment, update the remaining allocation percentages if (!Experiment.State.DRAFT.equals(experiment.getState())) { eventLog.postEvent(new BucketCreateEvent(user, experiment, newBucket)); BucketList updates = buckets.adjustAllocationPercentages(experiment, newBucket); buckets.updateBucketAllocBatch(experimentID, updates); } return getBucket(experimentID, newBucket.getLabel()); }
@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); } }