/** * Checks that an experiment has a state "draft" and throws an exception * if it doesn't * * @param experiment Experiment object containing experiment metadata */ public void ensureStateIsDraft(Experiment experiment) { Experiment.State state = experiment.getState(); if (!state.equals(Experiment.State.DRAFT)) { throw new InvalidExperimentStateException(experiment.getID(), Experiment.State.DRAFT, experiment.getState()); } }
.append(id, other.getID()) .append(creationTime, other.getCreationTime()) .append(modificationTime, other.getModificationTime())
private Builder(Experiment other) { this(other.getID()); instance.creationTime = copyDate(other.creationTime); instance.modificationTime = copyDate(other.modificationTime); instance.description = other.description; instance.hypothesisIsCorrect = other.hypothesisIsCorrect; instance.results = other.results; instance.rule = other.rule; instance.ruleJson = other.ruleJson; instance.samplingPercent = other.samplingPercent; instance.startTime = copyDate(other.startTime); instance.endTime = copyDate(other.endTime); instance.state = other.state; instance.label = other.label; instance.applicationName = other.applicationName; instance.isPersonalizationEnabled = other.isPersonalizationEnabled; instance.modelName = other.modelName; instance.modelVersion = other.modelVersion; instance.isRapidExperiment = other.isRapidExperiment; instance.userCap = other.userCap; instance.creatorID = other.creatorID; instance.tags = other.tags; instance.buckets = other.buckets; instance.sourceURL=other.sourceURL; instance.experimentType=other.experimentType; }
@SuppressWarnings({"unchecked", "rawtypes"}) private List<Map> queryDatabase() { String query = "select day from experiment_rollup where experiment_id = ? "; if (cumulative) { query += "and cumulative = ? "; } query += "order by day desc limit ?"; if (cumulative) { return transaction.select(query, experiment.getID(), 1, 1); } else { return transaction.select(query, experiment.getID(), 1); } }
@Override public AssignmentCounts getBucketAssignmentCount(Experiment experiment) { Result<com.intuit.wasabi.repository.cassandra.pojo.count.BucketAssignmentCount> result; try { result = bucketAssignmentCountAccessor.selectBy(experiment.getID().getRawID()); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not fetch the bucket assignment counts for experiment " + experiment.getID(), e); } return getBucketAssignmentCountFromCassandraResult(experiment.getID(), result); }
@Override public void deleteAssignment(Experiment experiment, User.ID userID, Context context, Application.Name appName, Assignment currentAssignment) { // Deletes the assignment data across all the relevant tables in a consistent manner //Note: Only removing the use of user_assignment & user_assignment_bu_userid tables. A separate card is created to completely remove these tables. //deleteUserFromLookUp(experiment.getID(), userID, context); //deleteAssignmentOld(experiment.getID(), userID, context, appName, currentAssignment.getBucketLabel()); //Updating the assignment bucket counts by -1 in a asynchronous AssignmentCountEnvelope thread // false to subtract 1 from the count for the bucket boolean countUp = false; assignmentsCountExecutor.execute(new AssignmentCountEnvelope(this, experimentRepository, dbRepository, experiment, currentAssignment, countUp, eventLog, null, assignUserToExport, assignBucketCount)); removeIndexExperimentsToUser(userID, experiment.getID(), context, appName); }
protected boolean checkMutex(Experiment experiment, Table<Experiment.ID, Experiment.Label, String> userAssignments, Map<Experiment.ID, List<Experiment.ID>> exclusivesList) { //if the experiment exists in the database and is in a valid MUTEX state if (experiment != null && (experiment.getState() == Experiment.State.RUNNING || experiment.getState() == Experiment.State.PAUSED)) { //get experiments which are mutually exclusive List<Experiment.ID> exclusiveIDs = exclusivesList.get(experiment.getID()); //get all experiments to which this user is assigned Set<Experiment.ID> preAssign = getNonNullUserAssignments(exclusivesList.get(experiment.getID()), userAssignments); //iterate over the mutex experiments for (Experiment.ID exp : exclusiveIDs) { //check if the user is in the experiment if (preAssign.contains(exp)) { //return a response that the user cannot be assigned return false; } } } return true; }
/** * {@inheritDoc} */ @Override public void updateStateIndex(Experiment experiment) { LOGGER.debug("update state index experiment {} ", experiment); try { updateStateIndex(experiment.getID(), experiment.getState() != State.DELETED ? ExperimentState.NOT_DELETED : ExperimentState.DELETED); } catch (Exception e) { LOGGER.error("update state index experiment {} ", experiment, e); throw new RepositoryException("Exception while updating state index: " + e, e); } }
/** * {@inheritDoc} */ @Override public void checkForIllegalUpdate(Experiment experiment, Experiment updates) { // Throw an exception if ID, ModificationTime or CreationTime is being updated. if (updates.getID() != null && !updates.getID().equals(experiment.getID())) { throw new IllegalArgumentException("Invalid experimentID \"" + updates.getID() + "\" " + "Cannot change experiment ID"); } if (updates.getCreationTime() != null && !updates.getCreationTime().equals(experiment.getCreationTime())) { throw new IllegalArgumentException("Invalid creationTime \"" + updates.getCreationTime() + "\" " + "Experiment creation time cannot be modified"); } if (updates.getModificationTime() != null && !updates.getModificationTime().equals(experiment.getModificationTime())) { throw new IllegalArgumentException("Invalid modificationTime \"" + updates.getModificationTime() + "\" " + "Experiment modification time cannot be modified"); } }
private void validateExperimentState(Experiment experiment) { Experiment.State state = experiment.getState(); if (!(state.equals(Experiment.State.PAUSED) || state.equals(Experiment.State.RUNNING) || state.equals(Experiment.State.DRAFT))) { Set<Experiment.State> desiredStates = new HashSet<>(); desiredStates.add(Experiment.State.DRAFT); desiredStates.add(Experiment.State.PAUSED); desiredStates.add(Experiment.State.RUNNING); throw new InvalidExperimentStateException(experiment.getID(), desiredStates, experiment.getState()); } }
/** * {@inheritDoc} */ @Override public void updateSegmentationRule(Experiment experiment, UserInfo user) { Rule oldRule = ruleCache.getRule(experiment.getID()); Rule newRule; if (experiment.getRule() != null && experiment.getRule().length() != 0) { newRule = new RuleBuilder().parseExpression(experiment.getRule()); ruleCache.setRule(experiment.getID(), newRule); LOGGER.debug("Segmentation rule of " + experiment.getID() + " updated from " + (oldRule != null ? oldRule.getExpressionRepresentation() : null) + " to " + (newRule != null ? newRule.getExpressionRepresentation() : null)); } else { ruleCache.clearRule(experiment.getID()); LOGGER.debug("Segmentation rule of " + experiment.getID() + " cleared " + (oldRule != null ? oldRule.getExpressionRepresentation() : null)); } }
@Override public void updateBucketAssignmentCount(Experiment experiment, Assignment assignment, boolean countUp) { Optional<Bucket.Label> labelOptional = Optional.ofNullable(assignment.getBucketLabel()); try { if (countUp) { bucketAssignmentCountAccessor.incrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } else { bucketAssignmentCountAccessor.decrementCountBy(experiment.getID().getRawID(), labelOptional.orElseGet(() -> NULL_LABEL).toString() ); } } catch (WriteTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not update the bucket count for experiment " + experiment.getID() + " bucket " + labelOptional.orElseGet(() -> NULL_LABEL).toString(), e); } }
/** * {@inheritDoc} */ @Override public ExperimentList getExclusions(Experiment.ID experimentID) { // Throw an exception if the input experiment is not valid final Experiment expID = experiments.getExperiment(experimentID); if (expID.getID() == null) { throw new ExperimentNotFoundException(experimentID); } return mutexRepository.getExclusions(experimentID); }
private Builder(Experiment other, Integer priority) { this(other.getID()); instance.creationTime = copyDate(other.getCreationTime()); instance.modificationTime = copyDate(other.getModificationTime()); instance.setDescription(other.getDescription()); instance.setSamplingPercent(other.getSamplingPercent()); instance.setRule(other.getRule()); instance.setStartTime(copyDate(other.getStartTime())); instance.setEndTime(copyDate(other.getEndTime())); instance.setState(other.getState()); instance.setLabel(other.getLabel()); instance.setApplicationName(other.getApplicationName()); instance.setPriority(priority); instance.setIsPersonalizationEnabled(other.getIsPersonalizationEnabled()); instance.setModelName(other.getModelName()); instance.setModelVersion(other.getModelVersion()); instance.isRapidExperiment = other.getIsRapidExperiment(); instance.userCap = other.getUserCap(); instance.creatorID = other.getCreatorID(); instance.tags = other.getTags(); }
/** * Checks that an experiment has a state "draft" and throws an exception * if it doesn't * * @param experiment Experiment object containing experiment metadata */ public void ensureStateIsDraft(Experiment experiment) { Experiment.State state = experiment.getState(); if (!state.equals(Experiment.State.DRAFT)) { throw new InvalidExperimentStateException(experiment.getID(), Experiment.State.DRAFT, experiment.getState()); } }
/** * {@inheritDoc} */ @Override public Experiment updateExperimentState(Experiment experiment, State state) { LOGGER.debug("Updating experiment {} state {} ", new Object[]{experiment, state}); validator.validateExperiment(experiment); try { // Note that this timestamp gets serialized as mulliseconds from // the epoch, so timezone is irrelevant final Date NOW = new Date(); experimentAccessor.updateExperiment(state.name(), NOW, experiment.getID().getRawID()); experiment = Experiment.from(experiment).withState(state).build(); // Point the experiment index to this experiment updateExperimentLabelIndex(experiment.getID(), experiment.getApplicationName(), experiment.getLabel(), experiment.getStartTime(), experiment.getEndTime(), experiment.getState()); updateStateIndex(experiment); } catch (Exception e) { LOGGER.error("Error while updating experiment {} state {} ", new Object[]{experiment, state}, e); throw new RepositoryException("Could not update experiment with ID \"" + experiment.getID() + "\"" + " to state " + state.toString(), e); } return experiment; }
@Override public Experiment updateExperimentState(Experiment experiment, State state) throws RepositoryException { validator.validateExperiment(experiment); final String SQL = "update experiment " + "set state=? where id=?"; int rowCount = newTransaction().update( SQL, state.toString(), experiment.getID()); if (rowCount > 1) { throw new RepositoryException("Concurrent updates; please retry"); } if (rowCount < 1) { throw new RepositoryException("No rows were updated"); } return experiment; }
/** * Creates the ExperimentDetail with a given Experiment and the total number of users. * * @param exp the experiment that provides the basic information */ public ExperimentDetail(Experiment exp) { this(exp.getID(), exp.getState(), exp.getLabel(), exp.getApplicationName(), exp.getModificationTime(), exp.getStartTime(), exp.getEndTime(), exp.getDescription(), exp.getTags()); }
/** * {@inheritDoc} */ @Override public Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName) { try { List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = experimentAccessor.getExperimentByAppName(appName.toString()).all(); Table<Experiment.ID, Experiment.Label, Experiment> result = HashBasedTable.create(); for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { Experiment experiment = ExperimentHelper.makeExperiment(experimentPojo); if (experiment.getState() != State.TERMINATED && experiment.getState() != State.DELETED) { result.put(experiment.getID(), experiment.getLabel(), experiment); } } return result; } catch (Exception e) { throw new RepositoryException("Could not retrieve experiment list " + appName.toString() + "because: " + e, e); } }
private Builder(Experiment other, Integer priority) { this(other.getID()); instance.creationTime = copyDate(other.getCreationTime()); instance.modificationTime = copyDate(other.getModificationTime()); instance.setDescription(other.getDescription()); instance.setSamplingPercent(other.getSamplingPercent()); instance.setRule(other.getRule()); instance.setStartTime(copyDate(other.getStartTime())); instance.setEndTime(copyDate(other.getEndTime())); instance.setState(other.getState()); instance.setLabel(other.getLabel()); instance.setApplicationName(other.getApplicationName()); instance.setPriority(priority); instance.setIsPersonalizationEnabled(other.getIsPersonalizationEnabled()); instance.setModelName(other.getModelName()); instance.setModelVersion(other.getModelVersion()); instance.isRapidExperiment = other.getIsRapidExperiment(); instance.userCap = other.getUserCap(); instance.creatorID = other.getCreatorID(); instance.tags = other.getTags(); }