@Override public ID deserialize(JsonParser parser, DeserializationContext context) throws IOException { return ID.valueOf(parser.getText()); } }
exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair()));
@Override public ID deserialize(JsonParser parser, DeserializationContext context) throws IOException { return ID.valueOf(parser.getText()); } }
if (expId != null) experimentId = Experiment.ID .valueOf(expId); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment id: "
for (com.intuit.wasabi.repository.cassandra.pojo.Application priority : UninterruptibleUtil.getUninterruptibly(applicationFuture).all()) { for (UUID uuid : priority.getPriorities()) { Experiment exp = experimentMap.get(Experiment.ID.valueOf(uuid)); if (nonNull(exp)) { prioritizedExperimentList.addPrioritizedExperiment(PrioritizedExperiment.from(exp, priorityValue).build());
Experiment.ID.valueOf((byte[]) experimentMap.get("id"));
exclusionMap.put(expId, new ArrayList<>()); UninterruptibleUtil.getUninterruptibly(exclusionFuture).all().forEach(exclusionPojo -> { exclusionMap.get(expId).add(Experiment.ID.valueOf(exclusionPojo.getPair()));
for (com.intuit.wasabi.repository.cassandra.pojo.Application priority : UninterruptibleUtil.getUninterruptibly(applicationFuture).all()) { for (UUID uuid : priority.getPriorities()) { Experiment exp = experimentMap.get(Experiment.ID.valueOf(uuid)); prioritizedExperimentList.addPrioritizedExperiment(PrioritizedExperiment.from(exp, priorityValue).build()); priorityValue += 1;
List<PageExperiment> pageExperimentsList = resultList.map(t -> { PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()
@Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException(new StringBuilder("Could not retrieve the experiments for applicationName:\"").append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } //TODO: make the experiment label part of the pageExperimentIndex to save a query per page return resultList .map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional.ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); } ).filter(t -> t.getLabel() != null) .collect(Collectors.toList()); }
/** * {@inheritDoc} */ @Override public List<Experiment.ID> getPriorityList(Application.Name applicationName) { LOGGER.debug("Getting priority list for {} ", applicationName); List<Experiment.ID> experimentIds = new ArrayList<>(); try { Result<com.intuit.wasabi.repository.cassandra.pojo.Application> priorities = prioritiesAccessor .getPriorities(applicationName.toString()); for (com.intuit.wasabi.repository.cassandra.pojo.Application priority : priorities .all()) { for (UUID uuid : priority.getPriorities()) { experimentIds.add(Experiment.ID.valueOf(uuid)); } } } catch (Exception e) { LOGGER.error("Exception while getting priority list for {} ", new Object[]{applicationName}, e); throw new RepositoryException( "Unable to retrieve the priority list for application: \"" + applicationName.toString() + "\"" + e); } return experimentIds; } }
/** * Populate existing user assignments for given user, application & context. * This method make use of provided experimentMap to eliminate the call to database to fetch experiment object. * * @param userID User Id * @param appLabel Application Label * @param context Environment context * @param experimentMap experiment map to fetch experiment label * @return List of assignments in term of pair of Experiment & Bucket label. */ @Override @Timed public List<Pair<Experiment, String>> getAssignments(User.ID userID, Application.Name appLabel, Context context, Map<Experiment.ID, Experiment> experimentMap) { final Stream<ExperimentUserByUserIdContextAppNameExperimentId> experimentUserStream = getUserIndexStream(userID.toString(), appLabel.toString(), context.getContext()); List<Pair<Experiment, String>> result = new ArrayList<>(); experimentUserStream.forEach((ExperimentUserByUserIdContextAppNameExperimentId t) -> { Experiment exp = experimentMap.get(Experiment.ID.valueOf(t.getExperimentId())); if (nonNull(exp)) { result.add(new ImmutablePair<>(exp, Optional.ofNullable(t.getBucket()).orElseGet(() -> "null"))); } else { LOGGER.debug("{} experiment id is not present in the experimentMap...", t.getExperimentId()); } }); return result; }
/** * {@inheritDoc} */ @Override public List<Experiment.ID> getFavorites(UserInfo.Username username) { // Remove favorites of now deleted experiments String updateSQL = "UPDATE user_experiment_properties INNER JOIN experiment " + "ON user_experiment_properties.experiment_id = experiment.id " + "SET user_experiment_properties.is_favorite = 0 " + "WHERE experiment.state = 'DELETED' AND user_experiment_properties.is_favorite = 1;"; transactionFactory.newTransaction().update(updateSQL); String sql = "SELECT experiment_id FROM user_experiment_properties WHERE user_id = ? AND is_favorite = 1;"; List list = transactionFactory.newTransaction().select(sql, username.toString()); List<Experiment.ID> favorites = new ArrayList<>(list.size()); for (Object row : list) { if (row instanceof Map) { Map map = (Map) row; if (map.get("experiment_id") instanceof byte[]) { favorites.add(Experiment.ID.valueOf((byte[]) map.get("experiment_id"))); } } } return favorites; }
@Override public List<PageExperiment> getExperimentsWithoutLabels(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try { Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor.selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport.stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve the experiments for applicationName:\"" + applicationName + "\", page:\"" + pageName, e); } return resultList.map(t -> { PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign() ); return builder.build(); } ).collect(Collectors.toList()); }
@Override public List<Experiment.ID> getExperiments() throws RepositoryException { final String SQL = "select id from experiment " + "where state != ? order by id"; try { List<Map<String, Object>> experiments = newTransaction().select(SQL, DELETED.toString()); List<Experiment.ID> result = new ArrayList<>(); for (Map<String, Object> experiment : experiments) { result.add(Experiment.ID.valueOf((byte[]) experiment.get("id"))); } return result; } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment IDs", e); } }
/** * {@inheritDoc} */ @Override public List<Experiment.ID> getExclusionList(Experiment.ID experimentID) { LOGGER.debug("Getting exclusions for {}", experimentID); List<Experiment.ID> exclusionIds = new ArrayList<>(); try { Result<Exclusion> exclusions = mutexAccessor.getExclusions(experimentID.getRawID()); for (Exclusion exclusion : exclusions.all()) { exclusionIds.add(Experiment.ID.valueOf(exclusion.getPair())); } } catch (Exception e) { LOGGER.error("Error while getting exclusions for {}", experimentID, e); throw new RepositoryException("Could not fetch exclusions for experiment \"" + experimentID + "\" ", e); } LOGGER.debug("Getting exclusions list of size {}", exclusionIds); return exclusionIds; }
/** * {@inheritDoc} */ @Override public List<Experiment.ID> getExperiments() { LOGGER.debug("Getting experiment ids which are live {}", ExperimentState.NOT_DELETED); try { // Get all experiments that are live Result<StateExperimentIndex> ids = stateExperimentIndexAccessor .selectByKey(ExperimentState.NOT_DELETED.name()); List<ID> experimentIds = ids.all().stream().map( sei -> Experiment.ID.valueOf(sei.getExperimentId())).collect(Collectors.toList()); return experimentIds; } catch (Exception e) { LOGGER.error("Error while getting experiment ids which are live {}", ExperimentState.NOT_DELETED, e); throw new RepositoryException("Could not retrieve experiments", e); } }
@Override @Timed public Assignment getAssignment(User.ID userID, Application.Name appName, Experiment.ID experimentID, Context context) { ListenableFuture<Result<ExperimentUserByUserIdContextAppNameExperimentId>> resultFuture = experimentUserIndexAccessor.asyncSelectBy(userID.toString(), appName.toString(), experimentID.getRawID(), context.toString()); Result<ExperimentUserByUserIdContextAppNameExperimentId> assignmentResult = UninterruptibleUtil.getUninterruptibly(resultFuture); Stream<ExperimentUserByUserIdContextAppNameExperimentId> assignmentResultStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(assignmentResult.iterator(), Spliterator.ORDERED), false); final Stream<Assignment.Builder> assignmentBuilderStream = assignmentResultStream.map(t -> { Assignment.Builder builder = Assignment.newInstance(Experiment.ID.valueOf(t.getExperimentId())) .withUserID(User.ID.valueOf(t.getUserId())) .withContext(Context.valueOf(t.getContext())); if (nonNull(t.getBucket()) && !t.getBucket().trim().isEmpty()) { builder.withBucketLabel(Bucket.Label.valueOf(t.getBucket())); } return builder; }); Optional<Assignment> assignmentOptional = getAssignmentFromStream(experimentID, userID, context, assignmentBuilderStream); return assignmentOptional.isPresent() ? assignmentOptional.get() : null; }
public static Experiment.ID makeExperimentId(UUID experimentId) { return Experiment.ID.valueOf(experimentId); }
public static Bucket makeBucket( com.intuit.wasabi.repository.cassandra.pojo.Bucket bucketPojo) { Bucket bucket = Bucket.newInstance(Experiment.ID.valueOf(bucketPojo.getExperimentId()), Bucket.Label.valueOf(bucketPojo.getLabel())) .withAllocationPercent(bucketPojo.getAllocation()) .withControl(bucketPojo.isControl()) .withDescription(bucketPojo.getDescription()) .withPayload(bucketPojo.getPayload()) .withState(Bucket.State.valueOf(bucketPojo.getState())) .build(); return bucket; }