.append(state, other.getState()) .append(label, other.getLabel()) .append(applicationName, other.getApplicationName()) .append(isPersonalizationEnabled, other.getIsPersonalizationEnabled()) .append(modelName, other.getModelName())
/** * {@inheritDoc} */ @Override public void appendToPriorityList(Experiment.ID experimentID) { Application.Name applicationName = experiments.getExperiment(experimentID).getApplicationName(); List<Experiment.ID> priorityList = prioritiesRepository.getPriorityList(applicationName); if (priorityList == null) { priorityList = new ArrayList<>(1); } // TODO: This current logic does not modify the priority list if the given experimentID already exists in the // priority list. Check if it would be better to move the given experiment to the end of the list if it // already exists if (!priorityList.contains(experimentID)) { priorityList.add(experimentID); prioritiesRepository.createPriorities(applicationName, priorityList); } }
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(); }
experiments.getExperiment(experimentID).getApplicationName(), READ);
Username userName = authorization.getUser(authorizationHeader); authorization.checkUserPermissions(userName, experiment.getApplicationName(), READ);
public List<Experiment.ID> cleanPriorityList(Application.Name applicationName, List<Experiment.ID> experimentIDs) { // Removing duplicates from the priority list Set<Experiment.ID> experimentSet = new LinkedHashSet<>(experimentIDs); // Removing the experiment ID's from the priority list that are invalid for (Experiment.ID experimentID : experimentIDs) { Experiment experiment = experiments.getExperiment(experimentID); // Remove DELETED experiments from the priorityList // Remove experiments not belonging to the pertinent application // Remove TERMINATED experiments from the priorityList if (experiment == null || !experiment.getApplicationName().equals(applicationName) || experiment.getState().equals(TERMINATED)) { experimentSet.remove(experimentID); } } // Adding valid (DRAFT, RUNNING, PAUSED) experiments from the experiment column family to the priorityList that // are missing List<Experiment> experimentList = experiments.getExperiments(applicationName); if (experimentList.size() != experimentSet.size()) { for (Experiment experiment : experimentList) { if (!experimentSet.contains(experiment.getID())) { experimentSet.add(experiment.getID()); } } } return new ArrayList<>(experimentSet); }
Experiment getAuthorizedExperimentById(final String authorizationHeader, final Experiment.ID experimentId) { UserInfo.Username userName = authorization.getUser(authorizationHeader); Experiment experiment = experiments.getExperiment(experimentId); if (experiment == null) { throw new ExperimentNotFoundException(experimentId); } authorization.checkUserPermissions(userName, experiment.getApplicationName(), READ); return experiment; }
private Application.Name getApplicationNameForModifyingPages(Experiment.ID experimentID) { Experiment experiment = experiments.getExperiment(experimentID); // Throw an exception if the experiment is not found if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } Application.Name applicationName = experiment.getApplicationName(); // Throw an exception if the experiment is in a TERMINATED state if (experiment.getState() == TERMINATED) { throw new InvalidExperimentStateException("Experiment must be in DRAFT, RUNNING or PAUSED states\"" + experimentID); } // Throw an exception if the experiment's end time has passed if (experiment.getEndTime().before(NOW)) { throw new IllegalArgumentException("Cannot modify pages of the experiment \"" + experimentID + "\" that has passed its end time"); } return applicationName; }
.append(state, other.getState()) .append(label, other.getLabel()) .append(applicationName, other.getApplicationName()) .append(isPersonalizationEnabled, other.getIsPersonalizationEnabled()) .append(modelName, other.getModelName())
/** * {@inheritDoc} */ @Override public void postPages(Experiment.ID experimentID, ExperimentPageList experimentPageList, UserInfo user) { Application.Name applicationName = getApplicationNameForModifyingPages(experimentID); pagesRepository.postPages(applicationName, experimentID, experimentPageList); Experiment experiment = experiments.getExperiment(experimentID); if (experiment != null) { List<String> pageNames = new ArrayList<>(); for (ExperimentPage experimentPage : experimentPageList.getPages()) { pageNames.add(experimentPage.getName().toString()); } String pageString = StringUtils.join(pageNames, ", "); eventLog.postEvent(new ExperimentChangeEvent(user, experiment, "pages", null, pageString)); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=PAGES_ADDED, applicationName={}, experimentName={}, configuration=[pages={}]", experiment.getApplicationName(), experiment.getLabel(), pageString); } }
/** * {@inheritDoc} */ @Override public void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates) { /* Throw an exception if the experiment is in RUNNING/PAUSED state and if applicationName or Label is being updated. Also, if startTime/endTime is being updated with a value that has already passed or when the established startTime/endTime has already passed. */ if (experiment.getState().equals(RUNNING) || experiment.getState().equals(PAUSED)) { if (updates.getApplicationName() != null && !updates.getApplicationName().equals(experiment.getApplicationName())) throw new IllegalArgumentException("Cannot change AppName when the experiment is not in DRAFT state"); if (updates.getLabel() != null && !updates.getLabel().equals(experiment.getLabel())) throw new IllegalArgumentException("Cannot change Label when the experiment is not in DRAFT state"); if (updates.getStartTime() != null && !updates.getStartTime().equals(experiment.getStartTime())) checkForIllegalExperimentStartTime(experiment, updates); if (updates.getEndTime() != null && !updates.getEndTime().equals(experiment.getEndTime())) checkForIllegalExperimentEndTime(experiment, updates); } }
/** * {@inheritDoc} */ @Override public void deletePage(Experiment.ID experimentID, Page.Name pageName, UserInfo user) { Application.Name applicationName = getApplicationNameForModifyingPages(experimentID); pagesRepository.deletePage(applicationName, experimentID, pageName); Experiment experiment = experiments.getExperiment(experimentID); if (experiment != null) { eventLog.postEvent(new ExperimentChangeEvent(user, experiment, "pages", pageName.toString(), null)); } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=PAGE_REMOVED, applicationName={}, experimentName={}, configuration=[pageName={}, userName={}]", experiment.getApplicationName(), experiment.getLabel(), pageName, user.getUsername()); }
/** * Gets the experiment for a given ID and checks if the user has permission. * If the user has READ permissions, the experiment is returned. Otherwise the authorization throws an exception. * <p> * Throws an exception if the experiment is not found. * * @param experimentID the experiment ID * @param username the username * @return the experiment */ /*test*/ Experiment getAuthorizedExperimentOrThrow(Experiment.ID experimentID, Username username) { Experiment experiment; if ((experiment = experiments.getExperiment(experimentID)) == null) { throw new ExperimentNotFoundException(experimentID); } authorization.checkUserPermissions(username, experiment.getApplicationName(), READ); // Hack: We need to make experiments compatible, converting CassandraExperiment experiment = Experiment.from(experiment).build(); return experiment; }
/** * {@inheritDoc} */ @Override public void updateExperimentState(final Experiment experiment, final Experiment.State state) { try { cassandraRepository.updateExperimentState(experiment, state); // To maintain consistency, revert the changes made in cassandra in case the mysql update fails try { databaseRepository.updateExperimentState(experiment, state); } catch (Exception exception) { cassandraRepository.updateExperimentState(experiment, experiment.getState()); throw exception; } eventLog.postEvent(new ExperimentChangeEvent(experiment, "state", experiment.getState().toString(), state.toString())); } catch (Exception exception) { LOGGER.error("Updating experiment state for experiment:{} failed with error:", experiment, exception); throw exception; } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=EXPERIMENT_STATE_UPDATED, applicationName={}, configuration=[experimentName={}, oldState={}, newState={}]", experiment.getApplicationName(), experiment.getLabel(), experiment.getState(), state); } }
/** * 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 void deleteExclusion(Experiment.ID expID_1, Experiment.ID expID_2, UserInfo user) { Experiment exp_1 = experiments.getExperiment(expID_1); Experiment exp_2 = experiments.getExperiment(expID_2); // Check that expID_1 is a valid experiment if (exp_1 == null) { throw new ExperimentNotFoundException(expID_1); } // Check that expID_2 is a valid experiment if (exp_2 == null) { throw new ExperimentNotFoundException(expID_2); } mutexRepository.deleteExclusion(expID_1, expID_2); eventLog.postEvent(new ExperimentChangeEvent(user, exp_1, "mutex", exp_2.getLabel().toString(), null)); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=MUTUAL_EXCLUSION_DELETED, applicationName={}, configuration=[experiment1={}, experiment2={}]", exp_1.getApplicationName(), exp_1.getLabel(), exp_2.getLabel()); }
/** * {@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 updateExperiment(Experiment experiment) throws RepositoryException { validator.validateExperiment(experiment); final String SQL = "update experiment " + "set description=?, sampling_percent=?, state=?, " + "label=?, start_time=?, end_time=?, app_name=? " + "where id=?"; int rowCount = newTransaction().update( SQL, experiment.getDescription() != null ? experiment.getDescription() : "", experiment.getSamplingPercent(), experiment.getState().toString(), experiment.getLabel().toString(), experiment.getStartTime(), experiment.getEndTime(), experiment.getApplicationName().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; }
experiment.getApplicationName(), experiment.getLabel(), bucket);
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(); }