use of org.apache.apex.examples.machinedata.data.MachineKey in project apex-malhar by apache.
the class DimensionGenerator method emitDimensions.
/**
* This function takes in the tuple from upstream operator and generates tuples with different dimension combinations
*
* @param tuple
*/
private void emitDimensions(MachineInfo tuple) {
MachineKey tupleKey = tuple.getMachineKey();
for (int i = 0; i < 64; i++) {
MachineKey machineKey = new MachineKey(tupleKey.getTimeKey(), tupleKey.getDay());
if ((i & 1) != 0) {
machineKey.setCustomer(tupleKey.getCustomer());
}
if ((i & 2) != 0) {
machineKey.setProduct(tupleKey.getProduct());
}
if ((i & 4) != 0) {
machineKey.setOs(tupleKey.getOs());
}
if ((i & 8) != 0) {
machineKey.setDeviceId(tupleKey.getDeviceId());
}
if ((i & 16) != 0) {
machineKey.setSoftware1(tupleKey.getSoftware1());
}
if ((i & 32) != 0) {
machineKey.setSoftware2(tupleKey.getSoftware2());
}
int cpu = tuple.getCpu();
int ram = tuple.getRam();
int hdd = tuple.getHdd();
MachineInfo machineInfo = new MachineInfo();
machineInfo.setMachineKey(machineKey);
machineInfo.setCpu((cpu < threshold) ? cpu : threshold);
machineInfo.setRam((ram < threshold) ? ram : threshold);
machineInfo.setHdd((hdd < threshold) ? hdd : threshold);
outputInline.emit(machineInfo);
output.emit(machineInfo);
}
}
use of org.apache.apex.examples.machinedata.data.MachineKey in project apex-malhar by apache.
the class CalculatorOperator method addDataToCache.
private void addDataToCache(MachineInfo tuple) {
MachineKey machineKey = tuple.getMachineKey();
if (!data.containsRow(machineKey)) {
data.put(machineKey, ResourceType.CPU, Lists.<Integer>newArrayList());
data.put(machineKey, ResourceType.RAM, Lists.<Integer>newArrayList());
data.put(machineKey, ResourceType.HDD, Lists.<Integer>newArrayList());
}
data.get(machineKey, ResourceType.CPU).add(tuple.getCpu());
data.get(machineKey, ResourceType.RAM).add(tuple.getRam());
data.get(machineKey, ResourceType.HDD).add(tuple.getHdd());
}
use of org.apache.apex.examples.machinedata.data.MachineKey in project apex-malhar by apache.
the class CalculatorOperatorTest method testMax.
public void testMax(CalculatorOperator oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.maxOutputPort.setSink(sortSink);
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
String timeKey = minuteDateFormat.format(date);
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
Integer vs = new Integer(1);
MachineKey mk = new MachineKey(timeKey, day, vs, vs, vs, vs, vs, vs, vs);
oper.beginWindow(0);
MachineInfo info = new MachineInfo(mk, 1, 1, 1);
oper.dataPort.process(info);
info.setCpu(2);
oper.dataPort.process(info);
info.setCpu(3);
oper.dataPort.process(info);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
LOG.debug(o.toString());
KeyValPair<TimeBucketKey, Map<ResourceType, Double>> keyValPair = (KeyValPair<TimeBucketKey, Map<ResourceType, Double>>) o;
Assert.assertEquals("emitted value for 'cpu' was ", 3, keyValPair.getValue().get(ResourceType.CPU), 0);
Assert.assertEquals("emitted value for 'hdd' was ", 1, keyValPair.getValue().get(ResourceType.HDD), 0);
Assert.assertEquals("emitted value for 'ram' was ", 1, keyValPair.getValue().get(ResourceType.RAM), 0);
}
LOG.debug("Done max testing\n");
}
Aggregations