Skip to content

Commit

Permalink
Merge branch 'develop' into feature/improveTestQuality
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaSuckro committed Dec 1, 2016
2 parents a94ed43 + 7a10730 commit b0fbf4e
Show file tree
Hide file tree
Showing 36 changed files with 1,046 additions and 389 deletions.
35 changes: 33 additions & 2 deletions bin/wasabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ reset=`tput sgr0`
export WASABI_OS=${WASABI_OS:-`uname -s`}
export WASABI_OSX="Darwin"
export WASABI_LINUX="Linux"
export CONTRIB_PLUGINS_TO_INSTALL=${CONTRIB_PLUGINS_TO_INSTALL:-}

usage() {
[ "${1}" ] && echo "${red}error: ${1}${reset}"
Expand Down Expand Up @@ -266,14 +267,44 @@ package() {
./bin/fpm.sh -n ${name} -v ${version} -p ${profile}

# FIXME: don't rebuild, cp dist/* target/*
(for contrib_dir in $CONTRIB_PLUGINS_TO_INSTALL; do
if [ -d contrib/$contrib_dir ]; then
echo "Installing plugin from contrib/$contrib_dir"
if [ -d contrib/$contrib_dir/plugins ]; then
cp -R contrib/$contrib_dir/plugins modules/ui/dist
fi
if [ -f contrib/$contrib_dir/scripts/plugins.js ]; then
if [ -f modules/ui/dist/scripts/plugins.js ] && [ `cat modules/ui/dist/scripts/plugins.js | wc -l` -gt 3 ]; then
echo Need to merge
# Get all but the last line of the current plugins.js file
sed -e "1,$(($(cat modules/ui/dist/scripts/plugins.js | wc -l) - 2))p;d" modules/ui/dist/scripts/plugins.js > tmp.txt
# Since this should end in a } we want to add a comma
echo ',' >> tmp.txt
# Copy all but the first and last lines of this plugins's config. This assumes first line defines var and array, last line ends array.
sed -e "2,$(($(cat contrib/$contrib_dir/scripts/plugins.js | wc -l) - 1))p;d" contrib/$contrib_dir/scripts/plugins.js >> tmp.txt
sed '$p;d' modules/ui/dist/scripts/plugins.js >> tmp.txt
cp tmp.txt modules/ui/dist/scripts/plugins.js
rm tmp.txt
else
echo Overwriting file
cp contrib/$contrib_dir/scripts/plugins.js modules/ui/dist/scripts
fi
fi
echo Merged in $contrib_dir
fi;
done)
(cd modules/ui; \
mkdir -p target; \
for f in app bower.json Gruntfile.js constants.json karma.conf.js karma-e2e.conf.js package.json test .bowerrc; do \
for f in app node_modules bower.json Gruntfile.js constants.json karma.conf.js karma-e2e.conf.js package.json test .bowerrc; do \
cp -r ${f} target; \
done; \
echo Getting merged plugins.js file and plugins directory; \
cp dist/scripts/plugins.js target/app/scripts/plugins.js; \
cp -R dist/plugins target/app; \
sed -i '' -e "s|http://localhost:8080|${server}|g" target/constants.json 2>/dev/null; \
sed -i '' -e "s|VERSIONLOC|${version}|g" target/app/index.html 2>/dev/null; \
(cd target; npm install; bower install --no-optional; grunt clean); \
#(cd target; npm install; bower install --no-optional; grunt clean); \
(cd target; grunt clean); \
(cd target; grunt build --target=develop --no-color) \
# ; grunt test); \
cp -r build target; \
Expand Down
2 changes: 1 addition & 1 deletion contrib/traffic-management-plugins/scripts/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ var wasabiUIPlugins = [
'ctrl': 'plugins/traffic-analysis/ctrl.js',
'templateUrl': 'plugins/traffic-analysis/template.html'
}
];
];
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2016 Intuit
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -15,19 +15,18 @@
*******************************************************************************/
package com.intuit.wasabi.analyticsobjects.wrapper;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.intuit.wasabi.experimentobjects.Application;
import com.intuit.wasabi.experimentobjects.Bucket;
import com.intuit.wasabi.experimentobjects.Experiment;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import static org.apache.commons.lang3.StringUtils.isEmpty;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonProperty;
import static org.apache.commons.lang3.StringUtils.isEmpty;

/**
* An ExperimentDetail is a wrapper class which holds additional information
Expand Down Expand Up @@ -55,12 +54,14 @@ public class ExperimentDetail {

private long totalNumberUsers;

private String description;


/**
* This class holds the details for the Buckets. This is especially interesting for
* running experiments that already have assigned users and corresponding action rates.
*/
public class BucketDetail{
public class BucketDetail {

@JsonProperty("isControl")
private boolean control;
Expand All @@ -84,19 +85,24 @@ public class BucketDetail{
private Boolean winnerSoFar = null;
private Boolean loserSoFar = null;

private String description;

/**
* Creates a BucketDetail with the basic information that are available for all buckets.
* @param label the label of the bucket
* @param control flag whether this bucket is control
* @param allocationPercent the allocation percentage for this bucket
*
* @param label the label of the bucket
* @param control flag whether this bucket is control
* @param allocationPercent the allocation percentage for this bucket
* @param description the description of the bucket
* @see Bucket for further information
*/
public BucketDetail(Bucket.Label label, boolean control, double allocationPercent, Bucket.State state){
public BucketDetail(Bucket.Label label, boolean control, double allocationPercent, Bucket.State state,
String description) {
setLabel(label);
setControl(control);
setAllocationPercent(allocationPercent);
setState(state);
setDescription(description);
}

public boolean isControl() {
Expand All @@ -112,7 +118,7 @@ public Bucket.Label getLabel() {
}

public void setLabel(Bucket.Label label) {
if(label != null && !isEmpty(label.toString()))
if (label != null && !isEmpty(label.toString()))
this.label = label;
else throw new IllegalArgumentException("The label of a bucket can not be empty");
}
Expand All @@ -122,7 +128,7 @@ public double getAllocationPercent() {
}

public void setAllocationPercent(double allocationPercent) {
if(allocationPercent >= 0.0 && allocationPercent <= 1.0)
if (allocationPercent >= 0.0 && allocationPercent <= 1.0)
this.allocationPercent = allocationPercent;
else throw new IllegalArgumentException("AllocationPercent must be between 0.0 and 1.0 for a bucket");
}
Expand All @@ -132,7 +138,7 @@ public double getActionRate() {
}

public void setActionRate(double actionRate) {
if(!Double.isNaN(actionRate)){
if (!Double.isNaN(actionRate)) {
this.actionRate = actionRate;
}
}
Expand All @@ -158,7 +164,7 @@ public long getCount() {
}

public void setCount(long count) {
if(count >= 0)
if (count >= 0)
this.count = count;
else throw new IllegalArgumentException("User count can not be smaller than 0");
}
Expand Down Expand Up @@ -186,46 +192,57 @@ public Bucket.State getState() {
public void setState(Bucket.State state) {
this.state = state;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}

/**
* 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){
public ExperimentDetail(Experiment exp) {
this(exp.getID(), exp.getState(), exp.getLabel(), exp.getApplicationName(),
exp.getModificationTime(), exp.getStartTime(), exp.getEndTime());
exp.getModificationTime(), exp.getStartTime(), exp.getEndTime(), exp.getDescription());
}

/**
* Creates the ExperimentDetail with explicit values for the necessary fields.
*
* @param id the id of the Experiment
* @param state the state of the Experiment
* @param label the Experiment label (name)
* @param appName the name of the Application this Experiment belongs to
* @param id the id of the Experiment
* @param state the state of the Experiment
* @param label the Experiment label (name)
* @param appName the name of the Application this Experiment belongs to
* @param modificationTime the last time the experiment was modified
* @param startTime the startTime of the experiment to determine the winner so far
* @param startTime the startTime of the experiment to determine the winner so far
* @param endTime the endtime of the experiment
* @param description the description of the experiment
*/
public ExperimentDetail(Experiment.ID id, Experiment.State state, Experiment.Label label,
Application.Name appName, Date modificationTime, Date startTime,
Date endTime){
Date endTime, String description) {
setId(id);
setState(state);
setLabel(label);
setApplicationName(appName);
setModificationTime(modificationTime);
setStartTime(startTime);
setEndTime(endTime);
setDescription(description);
}

public Experiment.ID getId() {
return id;
}

private void setId(Experiment.ID id) {
if(id != null && !isEmpty(id.toString()))
if (id != null && !isEmpty(id.toString()))
this.id = id;
else
throw new IllegalArgumentException("Can not create ExperimentDetail without an Experiment.ID");
Expand All @@ -236,7 +253,7 @@ public Experiment.State getState() {
}

private void setState(Experiment.State state) {
if(state != null)
if (state != null)
this.state = state;
else throw new IllegalArgumentException("Experiment.State is not allowed to be null for ExperimentDetail");
}
Expand All @@ -246,7 +263,7 @@ public Experiment.Label getLabel() {
}

private void setLabel(Experiment.Label label) {
if(label != null)
if (label != null)
this.label = label;
else throw new IllegalArgumentException("Experiment.Label is not allowed to be null for ExperimentDetail");
}
Expand All @@ -256,7 +273,7 @@ public Application.Name getApplicationName() {
}

private void setApplicationName(Application.Name applicationName) {
if(applicationName != null && !isEmpty(applicationName.toString()))
if (applicationName != null && !isEmpty(applicationName.toString()))
this.applicationName = applicationName;
else throw new IllegalArgumentException("Application Name can not be empty for ExperimentDetail");
}
Expand All @@ -282,7 +299,7 @@ public long getTotalNumberUsers() {
}

public void setTotalNumberUsers(long totalNumberUsers) {
if(totalNumberUsers > -1)
if (totalNumberUsers > -1)
this.totalNumberUsers = totalNumberUsers;
else throw new IllegalArgumentException("Total number of users has to be equal or greater than zero");
}
Expand Down Expand Up @@ -311,24 +328,33 @@ public void setEndTime(Date endTime) {
this.endTime = endTime;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

/**
* This method takes a list of buckets and transforms it to the {@link BucketDetail}s that are needed
* for later extension.
*
* @param buckets a list of {@link Bucket}s
*/
public void addBuckets(List<Bucket> buckets){
public void addBuckets(List<Bucket> buckets) {

List<BucketDetail> details = buckets.stream()
.map(b -> new BucketDetail(b.getLabel(), b.isControl(), b.getAllocationPercent(), b.getState()))
.map(b -> new BucketDetail(b.getLabel(), b.isControl(), b.getAllocationPercent(), b.getState(),
b.getDescription()))
.collect(Collectors.toList());

setBuckets(details);

}

@Override
public String toString(){
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

Expand Down

0 comments on commit b0fbf4e

Please sign in to comment.