Search in sources :

Example 11 with MachineKey

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);
    }
}
Also used : MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey)

Example 12 with MachineKey

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());
}
Also used : MachineKey(org.apache.apex.examples.machinedata.data.MachineKey)

Example 13 with MachineKey

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");
}
Also used : Calendar(java.util.Calendar) ResourceType(org.apache.apex.examples.machinedata.data.ResourceType) Date(java.util.Date) TimeBucketKey(org.apache.apex.malhar.lib.util.TimeBucketKey) MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) Map(java.util.Map) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink)

Aggregations

MachineKey (org.apache.apex.examples.machinedata.data.MachineKey)13 MachineInfo (org.apache.apex.examples.machinedata.data.MachineInfo)6 Calendar (java.util.Calendar)5 Date (java.util.Date)5 Map (java.util.Map)5 ResourceType (org.apache.apex.examples.machinedata.data.ResourceType)4 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)3 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)3 TimeBucketKey (org.apache.apex.malhar.lib.util.TimeBucketKey)3 AverageData (org.apache.apex.examples.machinedata.data.AverageData)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 MachineInfoAveragingOperator (org.apache.apex.examples.machinedata.operator.MachineInfoAveragingOperator)1 MachineInfoAveragingPrerequisitesOperator (org.apache.apex.examples.machinedata.operator.MachineInfoAveragingPrerequisitesOperator)1 SmtpOutputOperator (org.apache.apex.malhar.lib.io.SmtpOutputOperator)1