Search in sources :

Example 76 with Any

use of org.omg.CORBA.Any in project ACS by ACS-Community.

the class AnyAide method objectToCorbaAny.

/**
	 * Converts a generic Java object to a CORBA Any. May fail.
	 * 
	 * @param obj
	 *            Object to be converted to a CORBA any
	 * @return A CORBA any with obj's data embedded within it.
	 * @throws AcsJException
	 *             Thrown if there's some problem converting the object to an
	 *             any. TODO: make sure this works with enumerations.
	 */
public Any objectToCorbaAny(Object obj) throws AcsJException {
    if (obj != null && obj.getClass().isArray()) {
        return internalArrayToCorbaAny(obj);
    }
    Any retVal = m_containerServices.getAdvancedContainerServices().getAny();
    // null case
    if (obj == null) {
        retVal.insert_Object(null);
    } else // check against string
    if (obj instanceof String) {
        retVal.insert_string((String) obj);
    } else // check against double
    if (obj instanceof Double) {
        double value = ((Double) obj).doubleValue();
        retVal.insert_double(value);
    } else // check against long - CORBA long long and unsigned long long
    if (obj instanceof Long) {
        long value = ((Long) obj).longValue();
        retVal.insert_longlong(value);
    } else // check against integer - CORBA long or unsigned long
    if (obj instanceof Integer) {
        int value = ((Integer) obj).intValue();
        retVal.insert_long(value);
    } else // check against float
    if (obj instanceof Float) {
        float value = ((Float) obj).floatValue();
        retVal.insert_float(value);
    } else if (obj instanceof IDLEntity) {
        // and that this method will work.
        return complexObjectToCorbaAny((IDLEntity) obj);
    } else {
        Throwable cause = new Throwable("Bad arg of type " + obj.getClass().getName());
        throw new AcsJBadParameterEx(cause);
    }
    return retVal;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) IDLEntity(org.omg.CORBA.portable.IDLEntity) Any(org.omg.CORBA.Any)

Example 77 with Any

use of org.omg.CORBA.Any in project ACS by ACS-Community.

the class BlobberWorkerUnitTest method testStandardULongLong.

public void testStandardULongLong() throws Exception {
    // was 0, which is now illegal
    blobber.setCollectorIntervalSeconds(1);
    getTestWorker().setCanHandle(true);
    // Collector "TestCollector" is just a dummy to trick the worker to believe that 
    // there is a collector registered and start operating. "TestCollector" is not used at all.
    // The TestBlobberWorker creates its own single collector from which the blobber worker will get data. 
    getTestWorker().addCollector("TestCollector");
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    String propertyName = "VOLTAGE_MID_1";
    // Note that CORBA ulonglong means Java long.
    Any anyUp = create_any();
    long[] dataArrayUp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    uLongLongBlobData[] dataUp = new uLongLongBlobData[dataArrayUp.length];
    int index = 0;
    for (long value : dataArrayUp) {
        dataUp[index] = new uLongLongBlobData(BASE_TIME + index, value);
        index++;
    }
    uLongLongBlobDataSeqHelper.insert(anyUp, dataUp);
    MonitorBlob blobUp = new MonitorBlob(false, (short) 0, null, "wrong:" + propertyName, anyUp);
    MonitorBlob[] blobs = new MonitorBlob[1];
    blobs[0] = blobUp;
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    MonitorDataBlock[] blocks = new MonitorDataBlock[1];
    blocks[0] = block;
    getTestWorker().getCollector().setMonitorData(blocks);
    ComponentData data = getTestWorker().fetchData();
    String clob = BASE_TIME + "|1|" + (BASE_TIME + 1) + "|2|" + (BASE_TIME + 2) + "|3|" + (BASE_TIME + 3) + "|4|" + (BASE_TIME + 4) + "|5|" + (BASE_TIME + 5) + "|6|" + (BASE_TIME + 6) + "|7|" + (BASE_TIME + 7) + "|8|" + (BASE_TIME + 8) + "|9|" + (BASE_TIME + 9) + "|10\n";
    checkData(data, clob, 10, componentName, propertyName, serialNumber, startTime, stopTime);
    checkStatistics(data, 1.0, 10.0, 5.5, 3.0276503541);
}
Also used : MonitorBlob(alma.TMCDB.MonitorBlob) TMCDB.uLongLongBlobData(alma.TMCDB.uLongLongBlobData) ComponentData(alma.acs.monitoring.DAO.ComponentData) Any(org.omg.CORBA.Any) MonitorDataBlock(alma.TMCDB.MonitorDataBlock)

Example 78 with Any

use of org.omg.CORBA.Any in project ACS by ACS-Community.

the class BlobberWorkerUnitTest method testCorrelatorLong.

public void testCorrelatorLong() throws Exception {
    // was 0, which is now illegal
    blobber.setCollectorIntervalSeconds(1);
    getTestWorker().setCanHandle(true);
    // Collector "TestCollector" is just a dummy to trick the worker to believe that 
    // there is a collector registered and start operating. "TestCollector" is not used at all.
    // The TestBlobberWorker creates its own single collector from which the blobber worker will get data. 
    getTestWorker().addCollector("TestCollector");
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    String propertyName = "VOLTAGE_MID_1";
    // Note that CORBA long means Java int.
    Any anyUp = create_any();
    int[] dataArrayUp1 = { 1, 2, 3 };
    int[] dataArrayUp2 = { 11, 12, 13 };
    int[] dataArrayUp3 = { 21, 22, 23 };
    int[][] dataUpMatrix = { dataArrayUp1, dataArrayUp2, dataArrayUp3 };
    String[] serialNumbers = { "A", "B", "C" };
    longSeqBlobData[] dataUp = new longSeqBlobData[dataUpMatrix.length];
    int index = 0;
    for (int[] value : dataUpMatrix) {
        dataUp[index] = new longSeqBlobData(BASE_TIME + index, value);
        index++;
    }
    longSeqBlobDataSeqHelper.insert(anyUp, dataUp);
    MonitorBlob blobUp = new MonitorBlob(false, (short) 0, serialNumbers, "wrong:" + propertyName, anyUp);
    MonitorBlob[] blobs = new MonitorBlob[1];
    blobs[0] = blobUp;
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    MonitorDataBlock[] blocks = new MonitorDataBlock[1];
    blocks[0] = block;
    getTestWorker().getCollector().setMonitorData(blocks);
    ComponentData data = getTestWorker().fetchData();
    String clob = BASE_TIME + "|1|" + (BASE_TIME + 1) + "|11|" + (BASE_TIME + 2) + "|21\n";
    checkData(data, clob, 3, componentName, propertyName, "A", startTime, stopTime);
    checkStatistics(data, 1.0, 21.0, 11.0, 10.0);
    data = getTestWorker().fetchData();
    clob = BASE_TIME + "|2|" + (BASE_TIME + 1) + "|12|" + (BASE_TIME + 2) + "|22\n";
    propertyName = "" + propertyName;
    checkData(data, clob, 3, componentName, propertyName, "B", startTime, stopTime);
    checkStatistics(data, 2.0, 22.0, 12.0, 10.0);
    data = getTestWorker().fetchData();
    clob = BASE_TIME + "|3|" + (BASE_TIME + 1) + "|13|" + (BASE_TIME + 2) + "|23\n";
    propertyName = "" + propertyName;
    checkData(data, clob, 3, componentName, propertyName, "C", startTime, stopTime);
    checkStatistics(data, 3.0, 23.0, 13.0, 10.0);
}
Also used : ComponentData(alma.acs.monitoring.DAO.ComponentData) Any(org.omg.CORBA.Any) MonitorBlob(alma.TMCDB.MonitorBlob) TMCDB.longSeqBlobData(alma.TMCDB.longSeqBlobData) MonitorDataBlock(alma.TMCDB.MonitorDataBlock)

Example 79 with Any

use of org.omg.CORBA.Any in project ACS by ACS-Community.

the class BlobberWorkerUnitTest method testStandardPattern.

public void testStandardPattern() throws Exception {
    // was 0, which is now illegal
    blobber.setCollectorIntervalSeconds(1);
    getTestWorker().setCanHandle(true);
    // Collector "TestCollector" is just a dummy to trick the worker to believe that 
    // there is a collector registered and start operating. "TestCollector" is not used at all.
    // The TestBlobberWorker creates its own single collector from which the blobber worker will get data. 
    getTestWorker().addCollector("TestCollector");
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    String propertyName = "VOLTAGE_MID_1";
    Any anyUp = create_any();
    long[] dataArrayUp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    patternBlobData[] dataUp = new patternBlobData[dataArrayUp.length];
    int index = 0;
    for (long value : dataArrayUp) {
        dataUp[index] = new patternBlobData(BASE_TIME + index, (int) value);
        index++;
    }
    patternBlobDataSeqHelper.insert(anyUp, dataUp);
    MonitorBlob blobUp = new MonitorBlob(false, (short) 0, null, "wrong:" + propertyName, anyUp);
    MonitorBlob[] blobs = new MonitorBlob[1];
    blobs[0] = blobUp;
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    MonitorDataBlock[] blocks = new MonitorDataBlock[1];
    blocks[0] = block;
    getTestWorker().getCollector().setMonitorData(blocks);
    ComponentData data = getTestWorker().fetchData();
    String clob = BASE_TIME + "|1|" + (BASE_TIME + 1) + "|2|" + (BASE_TIME + 2) + "|3|" + (BASE_TIME + 3) + "|4|" + (BASE_TIME + 4) + "|5|" + (BASE_TIME + 5) + "|6|" + (BASE_TIME + 6) + "|7|" + (BASE_TIME + 7) + "|8|" + (BASE_TIME + 8) + "|9|" + (BASE_TIME + 9) + "|10\n";
    checkData(data, clob, 10, componentName, propertyName, serialNumber, startTime, stopTime);
    checkStatistics(data);
}
Also used : MonitorBlob(alma.TMCDB.MonitorBlob) ComponentData(alma.acs.monitoring.DAO.ComponentData) Any(org.omg.CORBA.Any) TMCDB.patternBlobData(alma.TMCDB.patternBlobData) MonitorDataBlock(alma.TMCDB.MonitorDataBlock)

Example 80 with Any

use of org.omg.CORBA.Any in project ACS by ACS-Community.

the class CorbaAnyExtractionTest method testExtractData_booleanSeqBlobDataSeq_singlevalued.

/**
	 * Test of extractData method for 'booleanSeqBlobDataSeq' data for a sequence property 
	 * that expands into multiple single-valued MPs.
	 */
@Test
public void testExtractData_booleanSeqBlobDataSeq_singlevalued() throws Exception {
    String propertyName = "SYSTEM_STATUS";
    Any any = create_any();
    boolean[] booleanData_time1 = { false, true, false };
    boolean[] booleanData_time2 = { true, true, true };
    boolean[][] booleanDataMatrix = { booleanData_time1, booleanData_time2 };
    booleanSeqBlobData[] booleanSeqBlobDataArray = createBooleanSeqBlobData(booleanDataMatrix);
    booleanSeqBlobDataSeqHelper.insert(any, booleanSeqBlobDataArray);
    monitorPointExpert.setMultivalued(propertyName, false);
    // Test the AnyExtractor stand-alone
    List<MonitorPointTimeSeries> extractedData = anyExtractor.extractData(any, propertyName);
    assertThat("Demultiplexing into several MonitorPointTimeSeries instances expected", extractedData, hasSize(booleanData_time1.length));
    for (int index = 0; index < extractedData.size(); index++) {
        // check one of the expanded logical properties at a time
        MonitorPointTimeSeries mpTs = extractedData.get(index);
        assertThat(mpTs.getCorbaTypeId(), equalTo("IDL:alma/TMCDB/booleanBlobDataSeq:1.0"));
        assertThat(mpTs.getMonitorPointIndex(), equalTo(index));
        List<MonitorPointValue> dataList = mpTs.getDataList();
        assertThat(dataList, hasSize(booleanDataMatrix.length));
        for (int i = 0; i < booleanDataMatrix.length; i++) {
            MonitorPointValue mpVal = dataList.get(i);
            assertThat(mpVal.getTime(), equalTo(BASE_TIME + i));
            // This should be the transpose of matrix booleanDataMatrix
            assertThat(mpVal.getData(), contains((Object) new Boolean(booleanDataMatrix[i][index])));
        }
    }
    logger.info("Validated booleanSeqBlobDataSeq interpreted as coming from a multiple single-valued MPs.");
    // As a variation we test also "BlobberWorker.createBlobData" which in real life surrounds the AnyExtractor call.
    // It includes generation of CLOB data.
    String componentName = "CONTROL/DV01/PSA";
    String serialNumber = "3456328928847";
    MonitorBlob blob = new MonitorBlob(false, (short) 0, new String[] {}, "wrong:" + propertyName, any);
    MonitorBlob[] blobs = new MonitorBlob[] { blob };
    long startTime = BASE_TIME + 100;
    long stopTime = BASE_TIME + 101;
    MonitorDataBlock block = new MonitorDataBlock(startTime, stopTime, componentName, serialNumber, blobs);
    String[] clobsExpected = new String[] { BASE_TIME + "|0|" + (BASE_TIME + 1) + "|1\n", BASE_TIME + "|1|" + (BASE_TIME + 1) + "|1\n", BASE_TIME + "|0|" + (BASE_TIME + 1) + "|1\n" };
    String[] statisticsExpected = { null, null, null };
    for (int i = 0; i < extractedData.size(); i++) {
        BlobData blobData = BlobberWorker.createBlobData(block, blob, extractedData.get(i), propertyName, serialNumber, logger);
        checkComponentData(blobData, clobsExpected[i], 2, componentName, propertyName, serialNumber, startTime, stopTime, i, statisticsExpected[i]);
    }
}
Also used : TMCDB.booleanSeqBlobData(alma.TMCDB.booleanSeqBlobData) MonitorPointValue(alma.acs.monitoring.MonitorPointValue) Any(org.omg.CORBA.Any) MonitorBlob(alma.TMCDB.MonitorBlob) TMCDB.floatBlobData(alma.TMCDB.floatBlobData) TMCDB.booleanSeqBlobData(alma.TMCDB.booleanSeqBlobData) TMCDB.longLongBlobData(alma.TMCDB.longLongBlobData) TMCDB.doubleBlobData(alma.TMCDB.doubleBlobData) TMCDB.doubleSeqBlobData(alma.TMCDB.doubleSeqBlobData) TMCDB.floatSeqBlobData(alma.TMCDB.floatSeqBlobData) MonitorPointTimeSeries(alma.acs.monitoring.MonitorPointTimeSeries) MonitorDataBlock(alma.TMCDB.MonitorDataBlock) Test(org.junit.Test)

Aggregations

Any (org.omg.CORBA.Any)107 MonitorBlob (alma.TMCDB.MonitorBlob)20 MonitorDataBlock (alma.TMCDB.MonitorDataBlock)20 ComponentData (alma.acs.monitoring.DAO.ComponentData)15 ServiceContext (org.omg.IOP.ServiceContext)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)10 SASContextBody (org.omg.CSI.SASContextBody)10 AcsJException (alma.acs.exceptions.AcsJException)9 Test (org.junit.Test)9 Description (org.omg.CORBA.ContainedPackage.Description)9 FormatMismatch (org.omg.IOP.CodecPackage.FormatMismatch)8 TypeMismatch (org.omg.IOP.CodecPackage.TypeMismatch)8 ContainedOperations (org.omg.CORBA.ContainedOperations)7 NVList (org.omg.CORBA.NVList)7 InvalidTypeForEncoding (org.omg.IOP.CodecPackage.InvalidTypeForEncoding)7 TMCDB.doubleBlobData (alma.TMCDB.doubleBlobData)6 TMCDB.doubleSeqBlobData (alma.TMCDB.doubleSeqBlobData)6 TMCDB.floatBlobData (alma.TMCDB.floatBlobData)6 MonitorPointTimeSeries (alma.acs.monitoring.MonitorPointTimeSeries)6 MonitorPointValue (alma.acs.monitoring.MonitorPointValue)6