提交 f5208064 编写于 作者: A ainilife

change test id from int to string

上级 4faf486b
......@@ -31,16 +31,16 @@ public class ABTestSampleServlet extends HttpServlet {
}
public static enum MyABTestId implements ABTestId {
CASE1(11);
CASE1("demo1");
private int m_id;
private String m_id;
private MyABTestId(int id) {
private MyABTestId(String id) {
m_id = id;
}
@Override
public int getValue() {
public String getValue() {
return m_id;
}
}
......
package com.dianping.cat.abtest;
public interface ABTestId {
public int getValue();
/**
* @return unique abtest name
*/
public String getValue();
}
......@@ -5,5 +5,5 @@ import java.util.Map;
import com.dianping.cat.abtest.spi.ABTestEntity;
public interface ABTestEntityRepository {
public Map<Integer, ABTestEntity> getEntities();
public Map<String, ABTestEntity> getEntities();
}
......@@ -32,15 +32,18 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
@Inject
private ClientConfigManager m_configManager;
@Inject
private int m_refreshTime = 60; //seconds
private String m_domain;
private Map<Integer, ABTestEntity> m_entities = new HashMap<Integer, ABTestEntity>();
private Map<String, ABTestEntity> m_entities = new HashMap<String, ABTestEntity>();
private Map<String, ABTestGroupStrategy> m_strategies = new HashMap<String, ABTestGroupStrategy>();
private String m_domain;
@Override
public Map<Integer, ABTestEntity> getEntities() {
public Map<String, ABTestEntity> getEntities() {
return m_entities;
}
......@@ -54,6 +57,10 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
m_domain = m_configManager.getFirstDomain().getId();
}
public void setRefreshTime(int refreshTime) {
m_refreshTime = refreshTime;
}
private void refresh() {
String clientIp = NetworkInterfaceManager.INSTANCE.getLocalHostAddress();
......@@ -103,7 +110,7 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
Cat.logError(e);
}
LockSupport.parkUntil(start + 6 * 1000L); // every minute
LockSupport.parkUntil(start + m_refreshTime * 1000L); // every minute
}
}
......@@ -114,14 +121,14 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
class ABTestVisitor extends BaseVisitor {
private String m_domain;
private Map<Integer, ABTestEntity> m_entities;
private Map<String, ABTestEntity> m_entities;
public ABTestVisitor(String domain) {
m_domain = domain;
m_entities = new HashMap<Integer, ABTestEntity>();
m_entities = new HashMap<String, ABTestEntity>();
}
public Map<Integer, ABTestEntity> getEntities() {
public Map<String, ABTestEntity> getEntities() {
return m_entities;
}
......@@ -158,7 +165,7 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
}
}
m_entities.put(entity.getId(), entity);
m_entities.put(entity.getName(), entity);
}
}
}
......
......@@ -7,44 +7,100 @@ import com.dianping.cat.abtest.model.entity.Run;
public class ABTestEntity {
private int m_id;
private String m_name;
private String m_groupStrategyName;
private Run m_run;
private ABTestGroupStrategy m_groupStrategy;
private String m_groupStrategyName;
public ABTestEntity() {
m_run = new Run();
m_run.setDisabled(true);
}
public ABTestEntity(Case _case, Run run) {
m_id = _case.getId();
m_name = _case.getName();
m_groupStrategyName = _case.getGroupStrategy();
m_run = run;
}
public String getGroupStrategyName() {
return m_groupStrategyName != null ? m_groupStrategyName : null;
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ABTestEntity other = (ABTestEntity) obj;
if (m_groupStrategy == null) {
if (other.m_groupStrategy != null)
return false;
} else if (!m_groupStrategy.equals(other.m_groupStrategy))
return false;
if (m_groupStrategyName == null) {
if (other.m_groupStrategyName != null)
return false;
} else if (!m_groupStrategyName.equals(other.m_groupStrategyName))
return false;
if (m_name == null) {
if (other.m_name != null)
return false;
} else if (!m_name.equals(other.m_name))
return false;
if (m_run == null) {
if (other.m_run != null)
return false;
} else if (!m_run.equals(other.m_run))
return false;
return true;
}
public Date getEndDate() {
return m_run.getEndDate();
}
public ABTestGroupStrategy getGroupStrategy() {
return m_groupStrategy;
}
public String getGroupStrategyConfiguration() {
return m_run.getGroupStrategyConfiguration() != null ? m_run.getGroupStrategyConfiguration() : null;
}
public Date getEndDate() {
return m_run.getEndDate();
public String getGroupStrategyName() {
return m_groupStrategyName != null ? m_groupStrategyName : null;
}
public String getName() {
return m_name;
}
public Run getRun() {
return m_run;
}
public Date getStartDate() {
return m_run.getStartDate();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((m_groupStrategy == null) ? 0 : m_groupStrategy.hashCode());
result = prime * result + ((m_groupStrategyName == null) ? 0 : m_groupStrategyName.hashCode());
result = prime * result + ((m_name == null) ? 0 : m_name.hashCode());
result = prime * result + ((m_run == null) ? 0 : m_run.hashCode());
return result;
}
public boolean isDisabled() {
return m_run.isDisabled();
}
public boolean isEligible(Date date) {
if (m_run.getDisabled() != null && m_run.getDisabled()) {
return false;
......@@ -67,83 +123,21 @@ public class ABTestEntity {
return true;
}
public boolean isDisabled() {
return m_run.isDisabled();
}
public void setDisabled(boolean disabled) {
m_run.setDisabled(disabled);
}
public ABTestGroupStrategy getGroupStrategy() {
return m_groupStrategy;
}
public void setGroupStrategy(ABTestGroupStrategy groupStrategy) {
m_groupStrategy = groupStrategy;
}
public void setId(int id){
m_id = id;
}
public int getId() {
return m_id;
}
public String getName() {
return m_name;
}
public Run getRun() {
return m_run;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((m_groupStrategyName == null) ? 0 : m_groupStrategyName.hashCode());
result = prime * result + m_id;
result = prime * result + ((m_name == null) ? 0 : m_name.hashCode());
result = prime * result + ((m_run == null) ? 0 : m_run.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ABTestEntity other = (ABTestEntity) obj;
if (m_groupStrategyName == null) {
if (other.m_groupStrategyName != null)
return false;
} else if (!m_groupStrategyName.equals(other.m_groupStrategyName))
return false;
if (m_id != other.m_id)
return false;
if (m_name == null) {
if (other.m_name != null)
return false;
} else if (!m_name.equals(other.m_name))
return false;
if (m_run == null) {
if (other.m_run != null)
return false;
} else if (!m_run.equals(other.m_run))
return false;
return true;
public void setName(String name) {
m_name = name;
}
@Override
public String toString() {
return "ABTestEntity [m_id=" + m_id + ", m_name=" + m_name + ", m_groupStrategyName=" + m_groupStrategyName
+ ", m_run=" + m_run +"]";
return "ABTestEntity [m_name=" + m_name + ", m_groupStrategyName=" + m_groupStrategyName + ", m_run=" + m_run
+ ", m_groupStrategy=" + m_groupStrategy + "]";
}
}
\ No newline at end of file
......@@ -30,8 +30,8 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
@Override
public ABTestContext getContext(ABTestId testId) {
Entry entry = m_threadLocal.get();
Map<Integer, DefaultABTestContext> map = entry.getContextMap();
int id = testId.getValue();
Map<String, DefaultABTestContext> map = entry.getContextMap();
String id = testId.getValue();
DefaultABTestContext ctx = map.get(id);
if (ctx == null) {
......@@ -64,18 +64,18 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
ctxList = new ArrayList<ABTestContext>(4);
List<ABTestEntity> entities = m_entityManager.getEntityList();
Map<Integer, DefaultABTestContext> ctxMap = m_threadLocal.get().getContextMap();
Map<String, DefaultABTestContext> ctxMap = m_threadLocal.get().getContextMap();
Date now = new Date();
for (ABTestEntity entity : entities) {
Entry entry = m_threadLocal.get();
int id = entity.getId();
DefaultABTestContext ctx = ctxMap.get(id);
String name = entity.getName();
DefaultABTestContext ctx = ctxMap.get(name);
if (ctx == null) {
ctx = createContext(entity, entry.getHttpServletRequest());
ctxMap.put(id, ctx);
ctxMap.put(name, ctx);
}
ctx.initialize(now);
......@@ -100,20 +100,20 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
entry.setHttpServletRequest(req);
Map<Integer, DefaultABTestContext> map = entry.getContextMap();
Map<String, DefaultABTestContext> map = entry.getContextMap();
for (DefaultABTestContext ctx : map.values()) {
ctx.setup(req);
}
}
static class Entry {
private Map<Integer, DefaultABTestContext> m_map = new HashMap<Integer, DefaultABTestContext>(4);
private Map<String, DefaultABTestContext> m_map = new HashMap<String, DefaultABTestContext>(4);
private List<ABTestContext> m_list;
private HttpServletRequest m_req;
public Map<Integer, DefaultABTestContext> getContextMap() {
public Map<String, DefaultABTestContext> getContextMap() {
return m_map;
}
......
......@@ -20,19 +20,19 @@ public class DefaultABTestEntityManager extends ContainerHolder implements ABTes
private ABTestEntityRepository m_repository;
@Override
public ABTestEntity getEntity(ABTestId id) {
ABTestEntity entity = m_repository.getEntities().get(id.getValue());
public ABTestEntity getEntity(ABTestId name) {
ABTestEntity entity = m_repository.getEntities().get(name.getValue());
if (entity == null) {
entity = new ABTestEntity();
entity.setId(id.getValue());
entity.setName(name.getValue());
entity.setDisabled(true);
m_repository.getEntities().put(id.getValue(), entity);
m_repository.getEntities().put(name.getValue(), entity);
StringBuilder sb = new StringBuilder();
sb.append("id ").append(id.getValue()).append(" doesn't exsit");
Cat.getProducer().logEvent("ABTest.IDMiss", "id-miss", sb.toString(), "");
sb.append("name ").append(name.getValue()).append(" doesn't exsit");
Cat.getProducer().logEvent("ABTest", "abtest-miss", sb.toString(), "");
}
return entity;
......
......@@ -23,7 +23,8 @@ class ABTestComponentConfigurator extends AbstractResourceConfigurator {
.req(ABTestEntityManager.class));
all.add(C(ABTestEntityRepository.class, HttpABTestEntityRepository.class) //
.req(ClientConfigManager.class));
.req(ClientConfigManager.class)
.config(E("refreshTime").value("6")));
all.add(C(ABTestEntityManager.class, DefaultABTestEntityManager.class) //
.req(ABTestEntityRepository.class));
......
......@@ -314,6 +314,9 @@
<component>
<role>com.dianping.cat.abtest.repository.ABTestEntityRepository</role>
<implementation>com.dianping.cat.abtest.repository.HttpABTestEntityRepository</implementation>
<configuration>
<refreshTime>6</refreshTime>
</configuration>
<requirements>
<requirement>
<role>com.dianping.cat.configuration.ClientConfigManager</role>
......
......@@ -26,18 +26,18 @@ public class SampleTest {
}
public static enum MyABTestId implements ABTestId {
CASE1(1001),
CASE1("1001"),
CASE2(1002);
CASE2("1002");
private int m_id;
private String m_id;
private MyABTestId(int id) {
private MyABTestId(String id) {
m_id = id;
}
@Override
public int getValue() {
public String getValue() {
return m_id;
}
}
......
......@@ -16,19 +16,19 @@ public class ABTestEntityManagerTest extends ComponentTestCase {
@Test
public void testGetEntity() throws Exception {
checkEntity(-1, null, null, null, null, false, false);
checkEntity(1001, "Mock1", "roundrobin", "This is the configuration", "2012-01-01 00:00:00", false, false);
checkEntity(1001, "Mock1", "roundrobin", "This is the configuration", "2013-04-10 18:00:00", true, false);
checkEntity("-1", null, null, null, null, false, false);
checkEntity("1001", "Mock1", "roundrobin", "This is the configuration", "2012-01-01 00:00:00", false, false);
checkEntity("1001", "Mock1", "roundrobin", "This is the configuration", "2013-04-10 18:00:00", true, false);
}
private void checkEntity(final int id, String expectedEntityName, String expectedGroupStrategy,
private void checkEntity(final String name, String expectedEntityName, String expectedGroupStrategy,
String expectedGroupStrategyConfiguration, String expectedDateStr, boolean expectedEligible,
boolean expectedDisabled) throws Exception {
ABTestEntityManager manager = lookup(ABTestEntityManager.class);
ABTestEntity entity = null;
for (ABTestEntity e : manager.getEntityList()) {
if (e.getId() == id) {
if (e.getName() == name) {
entity = e;
break;
}
......@@ -40,8 +40,6 @@ public class ABTestEntityManagerTest extends ComponentTestCase {
Assert.assertNotNull(entity);
Assert.assertEquals(id < 0 ? 0 : id, entity.getId());
if (expectedGroupStrategy != null) {
Assert.assertEquals(expectedGroupStrategy, entity.getGroupStrategyName());
}
......
......@@ -11,7 +11,7 @@ final class CatDatabaseConfigurator extends AbstractJdbcResourceConfigurator {
public List<Component> defineComponents() {
List<Component> all = new ArrayList<Component>();
all.add(defineJdbcDataSourceComponent("cat", "com.mysql.jdbc.Driver", "jdbc:mysql://192.168.7.43:3306/cat", "binlog", "binlog", "<![CDATA[useUnicode=true&autoReconnect=true]]>"));
all.add(defineJdbcDataSourceComponent("cat", "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1:3306/cat", "root", "", "<![CDATA[useUnicode=true&autoReconnect=true]]>"));
defineSimpleTableProviderComponents(all, "cat", com.dianping.cat.home.dal.report._INDEX.getEntityClasses());
defineDaoComponents(all, com.dianping.cat.home.dal.report._INDEX.getDaoClasses());
......
......@@ -43,13 +43,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
public static final String CHARSET = "UTF-8";
private final int m_pageSize = 5;
private Logger m_logger;
@Inject
private JspViewer m_jspViewer;
@Inject
private AbtestDao m_abtestDao;
......@@ -57,33 +50,74 @@ public class Handler implements PageHandler<Context>, LogEnabled {
private AbtestRunDao m_abtestRunDao;
@Inject
private ProjectDao m_projectDao;
private GroupStrategyDao m_groupStrategyDao;
@Inject
private GroupStrategyDao m_groupStrategyDao;
private ProjectDao m_projectDao;
@Inject
private JspViewer m_jspViewer;
private Logger m_logger;
private final int m_pageSize = 10;
@Override
@PayloadMeta(Payload.class)
@InboundActionMeta(name = "abtest")
public void handleInbound(Context ctx) throws ServletException, IOException {
if (ctx.getException() != null) {
return;
}
public void enableLogging(Logger logger) {
m_logger = logger;
}
Payload payload = ctx.getPayload();
Action action = payload.getAction();
private AbtestModel fetchAbtestModel() {
try {
AbtestModel abtestModel = new AbtestModel();
if (ctx.getHttpServletRequest().getMethod().equalsIgnoreCase("post")) {
if (action == Action.CREATE) {
handleCreateAction(ctx, payload);
} else if (action == Action.DETAIL) {
handleUpdateAction(ctx, payload);
List<AbtestRun> abtestRuns = m_abtestRunDao.findAll(AbtestRunEntity.READSET_FULL);
if (abtestRuns != null) {
Date now = new Date();
for (AbtestRun abtestRun : abtestRuns) {
AbtestStatus status = AbtestStatus.calculateStatus(abtestRun, now);
if (status == AbtestStatus.READY || status == AbtestStatus.RUNNING) {
// fetch Case and GroupStrategy
int caseId = abtestRun.getCaseId();
Abtest entity = m_abtestDao.findByPK(caseId, AbtestEntity.READSET_FULL);
int gid = entity.getGroupStrategy();
GroupStrategy groupStrategy = m_groupStrategyDao.findByPK(gid, GroupStrategyEntity.READSET_FULL);
Case _case = transform(abtestRun, entity, groupStrategy);
abtestModel.addCase(_case);
}
}
}
return abtestModel;
} catch (DalException e) {
m_logger.error("Error when find all AbtestRun", e);
Cat.logError(e);
}
return null;
}
if (action == Action.VIEW) {
handleStatusChangeAction(ctx);
private List<GroupStrategy> getAllGroupStrategys() {
try {
return m_groupStrategyDao.findAllByStatus(1, GroupStrategyEntity.READSET_FULL);
} catch (DalException e) {
m_logger.error(e.getMessage(), e);
Cat.logError(e);
}
return null;
}
private Map<String, List<Project>> getAllProjects() {
List<Project> projects = new ArrayList<Project>();
try {
projects = m_projectDao.findAll(ProjectEntity.READSET_FULL);
} catch (Exception e) {
m_logger.error(e.getMessage(), e);
Cat.logError(e);
}
// Collections.sort(projects, new ProjectCompartor());
return transform(projects);
}
private void handleCreateAction(Context ctx, Payload payload) {
......@@ -111,7 +145,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
run.setCaseId(abtest.getId());
m_abtestRunDao.insert(run);
} catch (DalException e) {
m_logger.error("Error when saving abtest", e);
Cat.logError(e);
......@@ -119,29 +152,59 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
}
private void handleUpdateAction(Context ctx, Payload payload) {
try {
AbtestRun run = new AbtestRun();
@Override
@PayloadMeta(Payload.class)
@InboundActionMeta(name = "abtest")
public void handleInbound(Context ctx) throws ServletException, IOException {
if (ctx.getException() != null) {
return;
}
run.setId(payload.getId());
run.setKeyId(payload.getId());
run.setCreator(payload.getOwner());
run.setStartDate(payload.getStartDate());
run.setEndDate(payload.getEndDate());
run.setDomains(StringUtils.join(payload.getDomains(), ','));
run.setStrategyConfiguration(payload.getStrategyConfig());
Date now = new Date();
run.setModifiedDate(now);
Payload payload = ctx.getPayload();
Action action = payload.getAction();
// only update run info, do not update abtest meta-info
m_abtestRunDao.updateByPK(run, AbtestRunEntity.UPDATESET_ALLOWED_MODIFYPART);
if (ctx.getHttpServletRequest().getMethod().equalsIgnoreCase("post")) {
if (action == Action.CREATE) {
handleCreateAction(ctx, payload);
} else if (action == Action.DETAIL) {
handleUpdateAction(ctx, payload);
}
}
} catch (DalException e) {
m_logger.error("Error when updating abtest", e);
Cat.logError(e);
ctx.setException(e);
if (action == Action.VIEW) {
handleStatusChangeAction(ctx);
}
}
@Override
@OutboundActionMeta(name = "abtest")
public void handleOutbound(Context ctx) throws ServletException, IOException {
Model model = new Model(ctx);
Payload payload = ctx.getPayload();
Action action = payload.getAction();
switch (action) {
case VIEW:
renderListModel(model, payload);
break;
case CREATE:
renderCreateModel(model);
break;
case DETAIL:
renderDetailModel(ctx, model, payload);
break;
case REPORT:
renderReportModel(ctx, model, payload);
break;
case MODEL:
renderModel(model);
break;
}
model.setAction(action);
model.setPage(SystemPage.ABTEST);
m_jspViewer.view(ctx, model);
}
private void handleStatusChangeAction(Context ctx) {
Payload payload = ctx.getPayload();
......@@ -154,27 +217,26 @@ public class Handler implements PageHandler<Context>, LogEnabled {
int runID = Integer.parseInt(id);
AbtestRun run = m_abtestRunDao.findByPK(runID, AbtestRunEntity.READSET_FULL);
if (payload.getDisableAbtest() == -1) { // suspend
if (payload.getDisableAbtest() == -1) {
// suspend abtest
if (!run.isDisabled()) {
run.setDisabled(true);
m_abtestRunDao.updateByPK(run, AbtestRunEntity.UPDATESET_STATUS);
} else {
error.addArgument(id, "Abtest " + id + " has been already suspended!");
error.addArgument(id, String.format("Abtest %d has been already suspended!", id));
}
} else if (payload.getDisableAbtest() == 1) { // resume
} else if (payload.getDisableAbtest() == 1) {
// resume abtest
if (run.isDisabled()) {
run.setDisabled(false);
m_abtestRunDao.updateByPK(run, AbtestRunEntity.UPDATESET_STATUS);
} else {
error.addArgument(id, "Abtest " + id + " has been already active!");
error.addArgument(id, String.format("Abtest %d has been already active!", id));
}
}
} catch (NumberFormatException e) {
} catch (Throwable e) {
// do nothing
Cat.logError(e);
} catch (DalException e) {
Cat.logError(e);
}
}
......@@ -187,97 +249,27 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
}
@Override
@OutboundActionMeta(name = "abtest")
public void handleOutbound(Context ctx) throws ServletException, IOException {
Model model = new Model(ctx);
Payload payload = ctx.getPayload();
Action action = payload.getAction();
switch (action) {
case VIEW:
renderListModel(model, payload);
break;
case CREATE:
renderCreateModel(model);
break;
case DETAIL:
renderDetailModel(ctx, model, payload);
break;
case REPORT:
renderReportModel(ctx, model, payload);
break;
case MODEL:
renderModel(model);
break;
}
model.setAction(action);
model.setPage(SystemPage.ABTEST);
m_jspViewer.view(ctx, model);
}
private void renderModel(Model model) {
model.setAbtestModel(fetchAbtestModel().toString());
}
private AbtestModel fetchAbtestModel() {
private void handleUpdateAction(Context ctx, Payload payload) {
try {
AbtestModel abtestModel = new AbtestModel();
List<AbtestRun> abtestRuns = m_abtestRunDao.findAll(AbtestRunEntity.READSET_FULL);
if (abtestRuns != null) {
Date now = new Date();
for (AbtestRun abtestRun : abtestRuns) {
AbtestStatus status = AbtestStatus.calculateStatus(abtestRun, now);
if (status == AbtestStatus.READY || status == AbtestStatus.RUNNING) {
// fetch Case and GroupStrategy
int caseId = abtestRun.getCaseId();
Abtest entity = m_abtestDao.findByPK(caseId, AbtestEntity.READSET_FULL);
int gid = entity.getGroupStrategy();
GroupStrategy groupStrategy = m_groupStrategyDao.findByPK(gid, GroupStrategyEntity.READSET_FULL);
Case _case = transform(abtestRun, entity, groupStrategy);
abtestModel.addCase(_case);
AbtestRun run = new AbtestRun();
}
}
}
run.setId(payload.getId());
run.setKeyId(payload.getId());
run.setCreator(payload.getOwner());
run.setStartDate(payload.getStartDate());
run.setEndDate(payload.getEndDate());
run.setDomains(StringUtils.join(payload.getDomains(), ','));
run.setStrategyConfiguration(payload.getStrategyConfig());
Date now = new Date();
run.setModifiedDate(now);
return abtestModel;
// only update run info, do not update abtest meta-info
m_abtestRunDao.updateByPK(run, AbtestRunEntity.UPDATESET_ALLOWED_MODIFYPART);
} catch (DalException e) {
m_logger.error("Error when find all AbtestRun", e);
m_logger.error("Error when updating abtest", e);
Cat.logError(e);
ctx.setException(e);
}
return null;
}
private Case transform(AbtestRun abtestRun, Abtest entity, GroupStrategy groupStrategy) throws DalException {
Case _case = new Case(entity.getId());
_case.setCreatedDate(entity.getCreationDate());
_case.setDescription(entity.getDescription());
_case.setGroupStrategy(groupStrategy.getName());
_case.setName(entity.getName());
_case.setOwner(entity.getOwner());
_case.setLastModifiedDate(entity.getModifiedDate());
for (String domain : StringUtils.split(entity.getDomains(), ',')) {
_case.addDomain(domain);
}
Run run = new Run(abtestRun.getId());
for (String domain : StringUtils.split(abtestRun.getDomains(), ',')) {
run.addDomain(domain);
}
run.setCreator(abtestRun.getCreator());
run.setDisabled(false);
run.setEndDate(abtestRun.getEndDate());
run.setGroupStrategyConfiguration(abtestRun.getStrategyConfiguration());
run.setStartDate(abtestRun.getStartDate());
_case.addRun(run);
return _case;
}
private void renderCreateModel(Model model) {
......@@ -293,21 +285,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
renderReportModel(ctx, model, payload);
}
private void renderReportModel(Context ctx, Model model, Payload payload) {
try {
int runId = payload.getId();
AbtestRun run = m_abtestRunDao.findByPK(runId, AbtestRunEntity.READSET_FULL);
Abtest abtest = m_abtestDao.findByPK(run.getCaseId(), AbtestEntity.READSET_FULL);
AbtestDaoModel abtestModel = new AbtestDaoModel(abtest, run);
model.setAbtest(abtestModel);
} catch (DalException e) {
Cat.logError(e);
m_logger.error("Error when fetching abtest", e);
ctx.setException(e);
}
}
private void renderListModel(Model model, Payload payload) {
List<ABTestReport> reports = new ArrayList<ABTestReport>();
AbtestStatus status = AbtestStatus.getByName(payload.getStatus(), null);
......@@ -318,14 +295,11 @@ public class Handler implements PageHandler<Context>, LogEnabled {
int createdCount = 0, readyCount = 0, runningCount = 0, terminatedCount = 0, suspendedCount = 0;
List<AbtestRun> runs = new ArrayList<AbtestRun>();
try {
runs = m_abtestRunDao.findAll(AbtestRunEntity.READSET_FULL);
} catch (DalException e) {
Cat.logError(e);
}
for (AbtestRun run : runs) {
try {
for (AbtestRun run : runs) {
Abtest abtest = m_abtestDao.findByPK(run.getCaseId(), AbtestEntity.READSET_FULL);
ABTestReport report = new ABTestReport(abtest, run, now);
......@@ -333,7 +307,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
if (status != null && report.getStatus() == status) {
filterReports.add(report);
}
switch (report.getStatus()) {
case CREATED:
createdCount++;
......@@ -351,9 +324,9 @@ public class Handler implements PageHandler<Context>, LogEnabled {
suspendedCount++;
break;
}
} catch (DalException e) {
Cat.logError(e);
}
} catch (Throwable e) {
Cat.logError(e);
}
model.setCreatedCount(createdCount);
......@@ -392,27 +365,50 @@ public class Handler implements PageHandler<Context>, LogEnabled {
model.setReports(reports);
}
private List<GroupStrategy> getAllGroupStrategys() {
private void renderModel(Model model) {
model.setAbtestModel(fetchAbtestModel().toString());
}
private void renderReportModel(Context ctx, Model model, Payload payload) {
try {
return m_groupStrategyDao.findAllByStatus(1, GroupStrategyEntity.READSET_FULL);
int runId = payload.getId();
AbtestRun run = m_abtestRunDao.findByPK(runId, AbtestRunEntity.READSET_FULL);
Abtest abtest = m_abtestDao.findByPK(run.getCaseId(), AbtestEntity.READSET_FULL);
AbtestDaoModel abtestModel = new AbtestDaoModel(abtest, run);
model.setAbtest(abtestModel);
} catch (DalException e) {
m_logger.error(e.getMessage(), e);
Cat.logError(e);
m_logger.error("Error when fetching abtest", e);
ctx.setException(e);
}
return null;
}
private Map<String, List<Project>> getAllProjects() {
List<Project> projects = new ArrayList<Project>();
private Case transform(AbtestRun abtestRun, Abtest entity, GroupStrategy groupStrategy) throws DalException {
Case _case = new Case(entity.getId());
_case.setCreatedDate(entity.getCreationDate());
_case.setDescription(entity.getDescription());
_case.setGroupStrategy(groupStrategy.getName());
_case.setName(entity.getName());
_case.setOwner(entity.getOwner());
_case.setLastModifiedDate(entity.getModifiedDate());
for (String domain : StringUtils.split(entity.getDomains(), ',')) {
_case.addDomain(domain);
}
try {
projects = m_projectDao.findAll(ProjectEntity.READSET_FULL);
} catch (Exception e) {
m_logger.error(e.getMessage(), e);
Cat.logError(e);
Run run = new Run(abtestRun.getId());
for (String domain : StringUtils.split(abtestRun.getDomains(), ',')) {
run.addDomain(domain);
}
// Collections.sort(projects, new ProjectCompartor());
return transform(projects);
run.setCreator(abtestRun.getCreator());
run.setDisabled(false);
run.setEndDate(abtestRun.getEndDate());
run.setGroupStrategyConfiguration(abtestRun.getStrategyConfiguration());
run.setStartDate(abtestRun.getStartDate());
_case.addRun(run);
return _case;
}
private Map<String, List<Project>> transform(List<Project> projects) {
......@@ -430,9 +426,4 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
return re;
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
}
}
......@@ -41,7 +41,7 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
private AbtestDaoModel m_abtest;
private String m_abtestModel;
public Model(Context ctx) {
super(ctx);
}
......@@ -156,12 +156,12 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
}
public String getAbtestModel() {
return m_abtestModel;
}
return m_abtestModel;
}
public void setAbtestModel(String abtestModel) {
m_abtestModel = abtestModel;
}
m_abtestModel = abtestModel;
}
public static class AbtestDaoModel {
......@@ -192,45 +192,44 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
}
public String getDescription() {
return m_abtest.getDescription();
}
return m_abtest.getDescription();
}
public int getGroupStrategy() {
return m_abtest.getGroupStrategy();
}
return m_abtest.getGroupStrategy();
}
public String getName() {
return m_abtest.getName();
}
return m_abtest.getName();
}
public String getOwner() {
return m_abtest.getOwner();
}
return m_abtest.getOwner();
}
public int getCaseId() {
return m_run.getCaseId();
}
return m_run.getCaseId();
}
public String getDomains() {
return m_run.getDomains();
}
return m_run.getDomains();
}
public Date getEndDate() {
return m_run.getEndDate();
}
return m_run.getEndDate();
}
public int getId() {
return m_run.getId();
}
return m_run.getId();
}
public Date getStartDate() {
return m_run.getStartDate();
}
return m_run.getStartDate();
}
public String getStrategyConfiguration() {
return m_run.getStrategyConfiguration();
}
return m_run.getStrategyConfiguration();
}
}
}
......@@ -49,12 +49,6 @@ public class Payload implements ActionPayload<SystemPage, Action> {
@FieldMeta("strategyConfig")
private String m_strategyConfig;
private String m_startDateStr;
private String m_endDateStr;
private SimpleDateFormat m_sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
@FieldMeta("enable")
private boolean m_enableAbtest;
......@@ -67,6 +61,12 @@ public class Payload implements ActionPayload<SystemPage, Action> {
@FieldMeta("id")
private int id;
private String m_startDateStr;
private String m_endDateStr;
private SimpleDateFormat m_sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
public void setAction(String action) {
if (action.equalsIgnoreCase(Action.REPORT.getName())) {
m_action = Action.getByName(action, Action.REPORT);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册