@Test(expected = ExperimentNotFoundException.class) public void testUpdateExperimentNull() { Experiment updateExp = null; expImpl.updateExperiment(experimentID, updateExp, UserInfo.from(UserInfo.Username.valueOf("user")).build()); }
@Override public Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user) { Experiment experiment = getExperiment(experimentID); Experiment oldExperiment = experiment; if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } Experiment.State currentState = experiment.getState(); Experiment.State desiredState = updates.getState(); experiments.checkStateTransition(experimentID, currentState, desiredState); experiments.checkForIllegalUpdate(experiment, updates); experiments.checkForIllegalTerminatedUpdate(experiment, updates); experiments.checkForIllegalPausedRunningUpdate(experiment, updates); List<ExperimentAuditInfo> changeList = new ArrayList<>(); Experiment.Builder builder = Experiment.from(experiment); boolean requiresUpdate = buildUpdatedExperiment(experiment, updates, builder, changeList); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=UPDATING_EXPERIMENT, applicationName={}, configuration={}", oldExperiment.getApplicationName(), oldExperiment); if (requiresUpdate) { experiment = builder.build(); boolean applicationNameChanged = !experiment.getApplicationName().equals(oldExperiment.getApplicationName ()); boolean segmentationRuleChanged = (experiment.getRule() != null && oldExperiment.getRule() != null) && !experiment.getRule().equals(oldExperiment.getRule()); validator.validateExperiment(experiment); Experiment updatedExperiment = cassandraRepository.updateExperiment(experiment); try { databaseRepository.updateExperiment(experiment); } catch (Exception e) { cassandraRepository.updateExperiment(oldExperiment); throw e; } experiment = updatedExperiment; if (applicationNameChanged) { priorities.removeFromPriorityList(oldExperiment.getApplicationName(), experimentID); priorities.appendToPriorityList(experimentID); } if (segmentationRuleChanged) { experiments.updateSegmentationRule(experiment, user); } if (!experiment.getState().equals(DRAFT)) { cassandraRepository.logExperimentChanges(experimentID, changeList); for (ExperimentAuditInfo experimentAuditInfo : changeList) { eventLog.postEvent(new ExperimentChangeEvent(user, experiment, experimentAuditInfo.getAttributeName(), experimentAuditInfo.getOldValue(), experimentAuditInfo.getNewValue())); } } if (desiredState != null && (desiredState.equals(TERMINATED) || desiredState.equals(DELETED))) { priorities.removeFromPriorityList(experiment.getApplicationName(), experimentID); pages.erasePageData(experiment.getApplicationName(), experimentID, user); if (desiredState.equals(DELETED)) { experiment = Experiment.from(experiment) .withState(DELETED) .build(); } } } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, Message=EXPERIMENT_UPDATED, applicationName={}, configuration={}", experiment.getApplicationName(), experiment); return experiment; }
ExperimentsImpl implements Experiments { @Override public Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user) { Experiment experiment = getExperiment(experimentID); Experiment oldExperiment = experiment; if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } Experiment.State currentState = experiment.getState(); Experiment.State desiredState = updates.getState(); experiments.checkStateTransition(experimentID, currentState, desiredState); experiments.checkForIllegalUpdate(experiment, updates); experiments.checkForIllegalTerminatedUpdate(experiment, updates); experiments.checkForIllegalPausedRunningUpdate(experiment, updates); List<ExperimentAuditInfo> changeList = new ArrayList<>(); Experiment.Builder builder = Experiment.from(experiment); boolean requiresUpdate = buildUpdatedExperiment(experiment, updates, builder, changeList); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=UPDATING_EXPERIMENT, applicationName={}, configuration={}", oldExperiment.getApplicationName(), oldExperiment); if (requiresUpdate) { experiment = builder.build(); boolean applicationNameChanged = !experiment.getApplicationName().equals(oldExperiment.getApplicationName ()); boolean segmentationRuleChanged = (experiment.getRule() != null && oldExperiment.getRule() != null) && !experiment.getRule().equals(oldExperiment.getRule()); validator.validateExperiment(experiment); Experiment updatedExperiment = cassandraRepository.updateExperiment(experiment); try { databaseRepository.updateExperiment(experiment); } catch (Exception e) { cassandraRepository.updateExperiment(oldExperiment); throw e; } experiment = updatedExperiment; if (applicationNameChanged) { priorities.removeFromPriorityList(oldExperiment.getApplicationName(), experimentID); priorities.appendToPriorityList(experimentID); } if (segmentationRuleChanged) { experiments.updateSegmentationRule(experiment, user); } if (!experiment.getState().equals(DRAFT)) { cassandraRepository.logExperimentChanges(experimentID, changeList); for (ExperimentAuditInfo experimentAuditInfo : changeList) { eventLog.postEvent(new ExperimentChangeEvent(user, experiment, experimentAuditInfo.getAttributeName(), experimentAuditInfo.getOldValue(), experimentAuditInfo.getNewValue())); } } if (desiredState != null && (desiredState.equals(TERMINATED) || desiredState.equals(DELETED))) { priorities.removeFromPriorityList(experiment.getApplicationName(), experimentID); pages.erasePageData(experiment.getApplicationName(), experimentID, user); if (desiredState.equals(DELETED)) { experiment = Experiment.from(experiment) .withState(DELETED) .build(); } } } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, Message=EXPERIMENT_UPDATED, applicationName={}, configuration={}", experiment.getApplicationName(), experiment); return experiment; } }
ExperimentsImpl implements Experiments { @Override public Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user) { Experiment experiment = getExperiment(experimentID); Experiment oldExperiment = experiment; if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } Experiment.State currentState = experiment.getState(); Experiment.State desiredState = updates.getState(); experiments.checkStateTransition(experimentID, currentState, desiredState); experiments.checkForIllegalUpdate(experiment, updates); experiments.checkForIllegalTerminatedUpdate(experiment, updates); experiments.checkForIllegalPausedRunningUpdate(experiment, updates); List<ExperimentAuditInfo> changeList = new ArrayList<>(); Experiment.Builder builder = Experiment.from(experiment); boolean requiresUpdate = buildUpdatedExperiment(experiment, updates, builder, changeList); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=UPDATING_EXPERIMENT, applicationName={}, configuration={}", oldExperiment.getApplicationName(), oldExperiment); if (requiresUpdate) { experiment = builder.build(); boolean applicationNameChanged = !experiment.getApplicationName().equals(oldExperiment.getApplicationName ()); boolean segmentationRuleChanged = (experiment.getRule() != null && oldExperiment.getRule() != null) && !experiment.getRule().equals(oldExperiment.getRule()); validator.validateExperiment(experiment); Experiment updatedExperiment = cassandraRepository.updateExperiment(experiment); try { databaseRepository.updateExperiment(experiment); } catch (Exception e) { cassandraRepository.updateExperiment(oldExperiment); throw e; } experiment = updatedExperiment; if (applicationNameChanged) { priorities.removeFromPriorityList(oldExperiment.getApplicationName(), experimentID); priorities.appendToPriorityList(experimentID); } if (segmentationRuleChanged) { experiments.updateSegmentationRule(experiment, user); } if (!experiment.getState().equals(DRAFT)) { cassandraRepository.logExperimentChanges(experimentID, changeList); for (ExperimentAuditInfo experimentAuditInfo : changeList) { eventLog.postEvent(new ExperimentChangeEvent(user, experiment, experimentAuditInfo.getAttributeName(), experimentAuditInfo.getOldValue(), experimentAuditInfo.getNewValue())); } } if (desiredState != null && (desiredState.equals(TERMINATED) || desiredState.equals(DELETED))) { priorities.removeFromPriorityList(experiment.getApplicationName(), experimentID); pages.erasePageData(experiment.getApplicationName(), experimentID, user); if (desiredState.equals(DELETED)) { experiment = Experiment.from(experiment) .withState(DELETED) .build(); } } } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, Message=EXPERIMENT_UPDATED, applicationName={}, configuration={}", experiment.getApplicationName(), experiment); return experiment; } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); }
ExperimentsImpl implements Experiments { @Override public Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user) { Experiment experiment = getExperiment(experimentID); Experiment oldExperiment = experiment; if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } Experiment.State currentState = experiment.getState(); Experiment.State desiredState = updates.getState(); experiments.checkStateTransition(experimentID, currentState, desiredState); experiments.checkForIllegalUpdate(experiment, updates); experiments.checkForIllegalTerminatedUpdate(experiment, updates); experiments.checkForIllegalPausedRunningUpdate(experiment, updates); List<ExperimentAuditInfo> changeList = new ArrayList<>(); Experiment.Builder builder = Experiment.from(experiment); boolean requiresUpdate = buildUpdatedExperiment(experiment, updates, builder, changeList); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=UPDATING_EXPERIMENT, applicationName={}, configuration={}", oldExperiment.getApplicationName(), oldExperiment); if (requiresUpdate) { experiment = builder.build(); boolean applicationNameChanged = !experiment.getApplicationName().equals(oldExperiment.getApplicationName ()); boolean segmentationRuleChanged = (experiment.getRule() != null && oldExperiment.getRule() != null) && !experiment.getRule().equals(oldExperiment.getRule()); validator.validateExperiment(experiment); Experiment updatedExperiment = cassandraRepository.updateExperiment(experiment); try { databaseRepository.updateExperiment(experiment); } catch (Exception e) { cassandraRepository.updateExperiment(oldExperiment); throw e; } experiment = updatedExperiment; if (applicationNameChanged) { priorities.removeFromPriorityList(oldExperiment.getApplicationName(), experimentID); priorities.appendToPriorityList(experimentID); } if (segmentationRuleChanged) { experiments.updateSegmentationRule(experiment, user); } if (!experiment.getState().equals(DRAFT)) { cassandraRepository.logExperimentChanges(experimentID, changeList); for (ExperimentAuditInfo experimentAuditInfo : changeList) { eventLog.postEvent(new ExperimentChangeEvent(user, experiment, experimentAuditInfo.getAttributeName(), experimentAuditInfo.getOldValue(), experimentAuditInfo.getNewValue())); } } if (desiredState != null && (desiredState.equals(TERMINATED) || desiredState.equals(DELETED))) { priorities.removeFromPriorityList(experiment.getApplicationName(), experimentID); pages.erasePageData(experiment.getApplicationName(), experimentID, user); if (desiredState.equals(DELETED)) { experiment = Experiment.from(experiment) .withState(DELETED) .build(); } } } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, Message=EXPERIMENT_UPDATED, applicationName={}, configuration={}", experiment.getApplicationName(), experiment); return experiment; } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); @Override ExperimentList getExperiments(); @Override List<Application.Name> getApplications(); @Override Map<Application.Name, Set<String>> getTagsForApplications(Collection<Application.Name> applicationNames); @Override Experiment getExperiment(Experiment.ID id); @Override Experiment getExperiment(Application.Name appName, Experiment.Label label); @Override List<Experiment> getExperiments(Application.Name appName); @Override void createExperiment(NewExperiment newExperiment, UserInfo user); @Override void checkStateTransition(Experiment.ID experimentID, Experiment.State currentState,
                                     Experiment.State desiredState); @Override void checkForIllegalUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates); @Override boolean buildUpdatedExperiment(Experiment experiment, Experiment updates, Experiment.Builder builder,
                                          List<ExperimentAuditInfo> changeList); @Override void updateSegmentationRule(Experiment experiment, UserInfo user); @Override Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user); @Override void updateExperimentState(final Experiment experiment, final Experiment.State state); }
ExperimentsImpl implements Experiments { @Override public Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user) { Experiment experiment = getExperiment(experimentID); Experiment oldExperiment = experiment; if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } Experiment.State currentState = experiment.getState(); Experiment.State desiredState = updates.getState(); experiments.checkStateTransition(experimentID, currentState, desiredState); experiments.checkForIllegalUpdate(experiment, updates); experiments.checkForIllegalTerminatedUpdate(experiment, updates); experiments.checkForIllegalPausedRunningUpdate(experiment, updates); List<ExperimentAuditInfo> changeList = new ArrayList<>(); Experiment.Builder builder = Experiment.from(experiment); boolean requiresUpdate = buildUpdatedExperiment(experiment, updates, builder, changeList); LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, message=UPDATING_EXPERIMENT, applicationName={}, configuration={}", oldExperiment.getApplicationName(), oldExperiment); if (requiresUpdate) { experiment = builder.build(); boolean applicationNameChanged = !experiment.getApplicationName().equals(oldExperiment.getApplicationName ()); boolean segmentationRuleChanged = (experiment.getRule() != null && oldExperiment.getRule() != null) && !experiment.getRule().equals(oldExperiment.getRule()); validator.validateExperiment(experiment); Experiment updatedExperiment = cassandraRepository.updateExperiment(experiment); try { databaseRepository.updateExperiment(experiment); } catch (Exception e) { cassandraRepository.updateExperiment(oldExperiment); throw e; } experiment = updatedExperiment; if (applicationNameChanged) { priorities.removeFromPriorityList(oldExperiment.getApplicationName(), experimentID); priorities.appendToPriorityList(experimentID); } if (segmentationRuleChanged) { experiments.updateSegmentationRule(experiment, user); } if (!experiment.getState().equals(DRAFT)) { cassandraRepository.logExperimentChanges(experimentID, changeList); for (ExperimentAuditInfo experimentAuditInfo : changeList) { eventLog.postEvent(new ExperimentChangeEvent(user, experiment, experimentAuditInfo.getAttributeName(), experimentAuditInfo.getOldValue(), experimentAuditInfo.getNewValue())); } } if (desiredState != null && (desiredState.equals(TERMINATED) || desiredState.equals(DELETED))) { priorities.removeFromPriorityList(experiment.getApplicationName(), experimentID); pages.erasePageData(experiment.getApplicationName(), experimentID, user); if (desiredState.equals(DELETED)) { experiment = Experiment.from(experiment) .withState(DELETED) .build(); } } } LOGGER.info("event=EXPERIMENT_METADATA_CHANGE, Message=EXPERIMENT_UPDATED, applicationName={}, configuration={}", experiment.getApplicationName(), experiment); return experiment; } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); @Override ExperimentList getExperiments(); @Override List<Application.Name> getApplications(); @Override Map<Application.Name, Set<String>> getTagsForApplications(Collection<Application.Name> applicationNames); @Override Experiment getExperiment(Experiment.ID id); @Override Experiment getExperiment(Application.Name appName, Experiment.Label label); @Override List<Experiment> getExperiments(Application.Name appName); @Override void createExperiment(NewExperiment newExperiment, UserInfo user); @Override void checkStateTransition(Experiment.ID experimentID, Experiment.State currentState,
                                     Experiment.State desiredState); @Override void checkForIllegalUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates); @Override boolean buildUpdatedExperiment(Experiment experiment, Experiment updates, Experiment.Builder builder,
                                          List<ExperimentAuditInfo> changeList); @Override void updateSegmentationRule(Experiment experiment, UserInfo user); @Override Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user); @Override void updateExperimentState(final Experiment experiment, final Experiment.State state);  }