/** * {@inheritDoc} */ @Override public Experiment getExperiment(Experiment.ID id) { return cassandraRepository.getExperiment(id); }
/** * {@inheritDoc} */ @Override public Bucket getBucket(Experiment.ID experimentID, Bucket.Label bucketLabel) { return cassandraRepository.getBucket(experimentID, bucketLabel); }
/** * {@inheritDoc} */ @Override public ExperimentList getExperiments() { List<Experiment.ID> experimentIDs = cassandraRepository.getExperiments(); return cassandraRepository.getExperiments(experimentIDs); }
Bucket bucket = cassandraRepository.getBucket(experimentID, bucketLabel); cassandraRepository.deleteBucket(experimentID, bucketLabel); try { databaseRepository.deleteBucket(experimentID, bucketLabel); .withState(bucket.getState()) .build(); cassandraRepository.createBucket(newBucket);
databaseRepository.createExperiment(newExperiment); cassandraRepository.createExperiment(newExperiment); } catch (Exception exceptionFromCassandra) { LOGGER.error("Exception occurred while creating an experiment in Cassandra... Experiment={}, UserInfo={}", newExperiment, user, exceptionFromCassandra); databaseRepository.deleteExperiment(newExperiment); } catch (Exception mysqlRollbackException) { LOGGER.error("An attempt to rollback of experiment in MySQL is failed...", mysqlRollbackException);
/** * {@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()); }
/** * {@inheritDoc} */ @Override public Experiment getExperiment(Application.Name appName, Experiment.Label label) { return cassandraRepository.getExperiment(appName, label); }
/** * {@inheritDoc} */ @Override public List<Experiment> getExperiments(Application.Name appName) { return cassandraRepository.getExperiments(appName); }
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 Experiment getExperiment(Experiment.ID id) { return databaseRepository.getExperiment(id); }
/** * {@inheritDoc} */ @Override public List<ExperimentDetail> getExperimentDetailsBase() { List<Experiment.ID> experimentIDs = cassandraRepository.getExperiments(); List<Experiment> exps = cassandraRepository.getExperiments(experimentIDs).getExperiments(); List<ExperimentDetail> details = new ArrayList<>(); exps.forEach(e -> details.add(new ExperimentDetail(e))); //add bucket information details.parallelStream().forEach(this::getBucketData); return details; }
boolean isBucketEmpty = false; if (bucketLabel != null && experimentRepository.getBucket(experimentID, t.getBucketLabel()).getState().equals(Bucket.State.EMPTY)) { bucketLabel = null; isBucketEmpty = true;
@Override public boolean doSegmentTest(Application.Name applicationName, Experiment.Label experimentLabel, Context context, SegmentationProfile segmentationProfile, HttpHeaders headers) { Experiment experiment = repository.getExperiment(applicationName, experimentLabel); if (experiment == null) { throw new IllegalArgumentException(new StringBuilder("Experiment not found for application \"") .append(applicationName).append("\" and label \"").append(experimentLabel).append("\"").toString()); } return doesProfileMatch(experiment, segmentationProfile, headers, context, true); }
/** * {@inheritDoc} */ @Override public ExperimentList getPageExperiments(Application.Name applicationName, Page.Name pageName) { ExperimentList result = new ExperimentList(); if (applicationName == null || applicationName.toString().isEmpty() || pageName == null || pageName.toString().isEmpty()) { return result; } else { List<PageExperiment> pageExperiments = pagesRepository.getExperiments(applicationName, pageName); List<Experiment.ID> expIDList = new ArrayList<>(); if (!pageExperiments.isEmpty()) { for (PageExperiment pageExperiment : pageExperiments) { Experiment.ID experimentID = pageExperiment.getId(); expIDList.add(experimentID); } } result = cassandraRepository.getExperiments(expIDList); } return result; }
/** * {@inheritDoc} */ @Override public AssignmentCounts getAssignmentCounts(Experiment.ID experimentID, Context context) { // Uses counters Experiment experiment = cassandraRepository.getExperiment(experimentID); if (Objects.isNull(experiment)) { throw new ExperimentNotFoundException(experimentID); } return assignmentRepository.getBucketAssignmentCount(experiment); }
/** * Get the experiment label based on experiment ID * If metadata cache is enabled then fetch from cache else fetch from database. * * @param experimentID * @return */ protected Experiment.Label getExperimentLabel(Experiment.ID experimentID) { if (isNull(experimentID)) return null; Experiment.Label label = null; Experiment exp = null; if (metadataCacheEnabled) { Optional<Experiment> expOptional = metadataCache.getExperimentById(experimentID); exp = expOptional.isPresent() ? expOptional.get() : null; } else { exp = repository.getExperiment(experimentID); } if (nonNull(exp)) { label = exp.getLabel(); } return label; }
/** * {@inheritDoc} */ @Override public StreamingOutput getAssignmentStream(Experiment.ID experimentID, Context context, Parameters parameters, Boolean ignoreNullBucket) { Experiment experiment = repository.getExperiment(experimentID); if (experiment == null) { throw new ExperimentNotFoundException(experimentID); } return assignmentsRepository.getAssignmentStream(experimentID, context, parameters, ignoreNullBucket); }
List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); // Fetches the relevant partitions for a given time window where the user assignments data resides. return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); }
/** * Get the experiment object for given application & experiment label. * <p> * If metadata cache is enabled then fetch from cache else fetch from database. * * @param applicationName * @param experimentLabel * @return experiment object */ protected Experiment getExperiment(Application.Name applicationName, Experiment.Label experimentLabel) { Experiment result = null; if (metadataCacheEnabled) { //First fetch experiment list sorted by priorities (contains non-deleted experiment-ids). //This experiment-priority list is the source of truth for ALL assignment flows while looking up experiment... Optional<PrioritizedExperimentList> prioritizedExperimentListOptional = metadataCache.getPrioritizedExperimentListMap(applicationName); if (prioritizedExperimentListOptional.isPresent()) { //Iterate as per experiment priority and look for the matching experiment by their label for (PrioritizedExperiment prioritizedExperiment : prioritizedExperimentListOptional.get().getPrioritizedExperiments()) { if (experimentLabel.equals(prioritizedExperiment.getLabel())) { //Upon match, get the complete experiment object from cache result = metadataCache.getExperimentById(prioritizedExperiment.getID()).orElse(null); break; } } } } else { result = repository.getExperiment(applicationName, experimentLabel); } return result; }