Skip to content

Commit

Permalink
fix issue #20, support multiple same operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jialinsun authored and ywang19 committed Oct 22, 2013
1 parent b7cdb60 commit a013bf0
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void initLimites() {
private void initMarks() {
Set<String> types = new LinkedHashSet<String>();
for (OperatorContext op : operatorRegistry)
types.add(getMarkType(op.getOpType(), op.getSampleType()));
types.add(getMarkType(op.getName(), op.getSampleType()));
for (String type : types)
currMarks.addMark(newMark(type));
for (String type : types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void init(String division, Config config) {

@Override
public String getSampleType() {
return getOpType();
return getName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

package com.intel.cosbench.driver.operator;

import static com.intel.cosbench.driver.util.Defaults.OPERATION_PREFIX;
import static com.intel.cosbench.driver.util.Defaults.OPERATION_SUFFIX;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.intel.cosbench.api.storage.StorageInterruptedException;
import com.intel.cosbench.bench.*;
import com.intel.cosbench.config.Config;
Expand All @@ -34,6 +39,7 @@
class Deleter extends AbstractOperator {

public static final String OP_TYPE = "delete";
public String name;

private ObjectPicker objPicker = new ObjectPicker();

Expand All @@ -45,25 +51,38 @@ public Deleter() {
protected void init(String division, Config config) {
super.init(division, config);
objPicker.init(division, config);
name = StringUtils.join(new Object[] {
config.get("opprefix", OPERATION_PREFIX), OP_TYPE,
config.get("opsuffix", OPERATION_SUFFIX) });
}

@Override
public String getOpType() {
return OP_TYPE;
}

@Override
public String getName() {
return name;
}

@Override
protected void operate(int idx, int all, Session session) {
String[] path = objPicker.pickObjPath(session.getRandom(), idx, all);
Sample sample = doDelete(path[0], path[1], config, session);
Sample sample = doDelete(path[0], path[1], config, session, name);
session.getListener().onSampleCreated(sample);
Date now = sample.getTimestamp();
Result result = new Result(now, OP_TYPE, sample.isSucc());
Result result = new Result(now, name, sample.isSucc());
session.getListener().onOperationCompleted(result);
}

public static Sample doDelete(String conName, String objName,
Config config, Session session) {
Config config, Session session) {
return doDelete(conName, objName, config, session, OP_TYPE);
}

public static Sample doDelete(String conName, String objName,
Config config, Session session, String opName) {
if (Thread.interrupted())
throw new AbortedException();

Expand All @@ -75,13 +94,13 @@ public static Sample doDelete(String conName, String objName,
throw new AbortedException();
} catch (Exception e) {
doLogErr(session.getLogger(), "fail to perform remove operation", e);
return new Sample(new Date(), OP_TYPE, false);
return new Sample(new Date(), opName, false);
}

long end = System.currentTimeMillis();

Date now = new Date(end);
return new Sample(now, OP_TYPE, true, end - start, 0L);
return new Sample(now, opName, true, end - start, 0L);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.*;
import org.apache.commons.lang.StringUtils;

import static com.intel.cosbench.driver.util.Defaults.OPERATION_PREFIX;
import static com.intel.cosbench.driver.util.Defaults.OPERATION_SUFFIX;
import com.intel.cosbench.api.storage.StorageInterruptedException;
import com.intel.cosbench.bench.*;
import com.intel.cosbench.config.Config;
Expand All @@ -39,6 +42,8 @@
class Reader extends AbstractOperator {

public static final String OP_TYPE = "read";

public String name;

private boolean hashCheck = false;

Expand All @@ -53,12 +58,21 @@ protected void init(String division, Config config) {
super.init(division, config);
objPicker.init(division, config);
hashCheck = config.getBoolean("hashCheck", false);
name = StringUtils.join(new Object[] {
config.get("opprefix", OPERATION_PREFIX), OP_TYPE,
config.get("opsuffix", OPERATION_SUFFIX) });
}

@Override
public String getOpType() {
return OP_TYPE;
}


@Override
public String getName() {
return name;
}

@Override
protected void operate(int idx, int all, Session session) {
Expand All @@ -67,7 +81,7 @@ protected void operate(int idx, int all, Session session) {
Sample sample = doRead(out, path[0], path[1], config, session);
session.getListener().onSampleCreated(sample);
Date now = sample.getTimestamp();
Result result = new Result(now, OP_TYPE, sample.isSucc());
Result result = new Result(now, name, sample.isSucc());
session.getListener().onOperationCompleted(result);
}

Expand All @@ -86,12 +100,12 @@ private Sample doRead(OutputStream out, String conName, String objName,
if (!hashCheck)
IOUtils.copyLarge(in, cout);
else if (!validateChecksum(conName, objName, session, in, cout))
return new Sample(new Date(), OP_TYPE, false);
return new Sample(new Date(), name, false);
} catch (StorageInterruptedException sie) {
throw new AbortedException();
} catch (Exception e) {
doLogErr(session.getLogger(), "fail to perform read operation", e);
return new Sample(new Date(), OP_TYPE, false);
return new Sample(new Date(), name, false);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(cout);
Expand All @@ -100,7 +114,7 @@ else if (!validateChecksum(conName, objName, session, in, cout))
long end = System.currentTimeMillis();

Date now = new Date(end);
return new Sample(now, OP_TYPE, true, end - start, cout.getByteCount());
return new Sample(now, name, true, end - start, cout.getByteCount());
}

private static boolean validateChecksum(String conName, String objName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CountingInputStream;
import org.apache.commons.lang.StringUtils;

import static com.intel.cosbench.driver.util.Defaults.OPERATION_PREFIX;
import static com.intel.cosbench.driver.util.Defaults.OPERATION_SUFFIX;
import com.intel.cosbench.api.storage.StorageInterruptedException;
import com.intel.cosbench.bench.*;
import com.intel.cosbench.config.Config;
Expand All @@ -39,6 +42,7 @@
class Writer extends AbstractOperator {

public static final String OP_TYPE = "write";
public String name;

private boolean chunked;
private boolean isRandom;
Expand All @@ -58,12 +62,20 @@ protected void init(String division, Config config) {
chunked = config.getBoolean("chunked", false);
isRandom = !config.get("content", "random").equals("zero");
hashCheck = config.getBoolean("hashCheck", false);
name = StringUtils.join(new Object[] {
config.get("opprefix", OPERATION_PREFIX), OP_TYPE,
config.get("opsuffix", OPERATION_SUFFIX) });
}

@Override
public String getOpType() {
return OP_TYPE;
}

@Override
public String getName() {
return name;
}

@Override
protected void operate(int idx, int all, Session session) {
Expand All @@ -73,15 +85,21 @@ protected void operate(int idx, int all, Session session) {
String[] path = objPicker.pickObjPath(random, idx, all);
RandomInputStream in = new RandomInputStream(size, random, isRandom,
hashCheck);
Sample sample = doWrite(in, len, path[0], path[1], config, session);
Sample sample = doWrite(in, len, path[0], path[1], config, session,
name);
session.getListener().onSampleCreated(sample);
Date now = sample.getTimestamp();
Result result = new Result(now, OP_TYPE, sample.isSucc());
Result result = new Result(now, name, sample.isSucc());
session.getListener().onOperationCompleted(result);
}

public static Sample doWrite(InputStream in, long length, String conName,
String objName, Config config, Session session) {
String objName, Config config, Session session) {
return doWrite(in, length, conName, objName, config, session, OP_TYPE);
}

public static Sample doWrite(InputStream in, long length, String conName,
String objName, Config config, Session session, String opName) {
if (Thread.interrupted())
throw new AbortedException();

Expand All @@ -96,15 +114,15 @@ public static Sample doWrite(InputStream in, long length, String conName,
throw new AbortedException();
} catch (Exception e) {
session.getLogger().error("fail to perform write operation", e);
return new Sample(new Date(), OP_TYPE, false);
return new Sample(new Date(), opName, false);
} finally {
IOUtils.closeQuietly(cin);
}

long end = System.currentTimeMillis();

Date now = new Date(end);
return new Sample(now, OP_TYPE, true, end - start, cin.getByteCount());
return new Sample(now, opName, true, end - start, cin.getByteCount());
}
/*
* public static Sample doWrite(byte[] data, String conName, String objName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import java.util.*;
import java.util.concurrent.*;

import org.apache.commons.lang.StringUtils;

import static com.intel.cosbench.driver.util.Defaults.OPERATION_PREFIX;
import static com.intel.cosbench.driver.util.Defaults.OPERATION_SUFFIX;
import com.intel.cosbench.api.auth.*;
import com.intel.cosbench.api.storage.*;
import com.intel.cosbench.config.*;
Expand Down Expand Up @@ -139,8 +143,15 @@ private static OperatorContext createOperatorContext(Operation op) {
private void initOpPicker() {
OperationPicker picker = new OperationPicker();
Mission mission = missionContext.getMission();
for (Operation op : mission)
picker.addOperation(op.getType(), op.getRatio());
for (Operation op : mission) {
Config config = KVConfigParser.parse(op.getConfig());
picker.addOperation(
StringUtils.join(new Object[] {
config.get("opprefix", OPERATION_PREFIX),
op.getType(),
config.get("opsuffix", OPERATION_SUFFIX) }),
op.getRatio());
}
missionContext.setOperationPicker(picker);
}

Expand Down Expand Up @@ -318,7 +329,7 @@ public void close() {
LOGGER.debug("!!!! mission op: "
+ missionContext.getReport().getAllMetrics()[i].getOpType()
+ "-"
+ missionContext.getReport().getAllMetrics()[i].getOpType());
+ missionContext.getReport().getAllMetrics()[i].getSampleType());
if (missionContext.getReport().getAllMetrics()[i].getSampleCount() == 0
&& missionContext.getReport().getAllMetrics()[i]
.getTotalSampleCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.intel.cosbench.driver.util;

interface Defaults {
public interface Defaults {

String CONTAINER_PREFIX = "mycontainers_";

Expand All @@ -26,5 +26,9 @@ interface Defaults {
String OBJECT_PREFIX = "myobjects_";

String OBJECT_SUFFIX = null;

String OPERATION_SUFFIX = null;

String OPERATION_PREFIX = null;

}

0 comments on commit a013bf0

Please sign in to comment.