From b109c218ab7db28fd1cbe62c808496dfdedad809 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 18 Jul 2018 11:23:20 +0100 Subject: Fix incorrect naming on context plugins This change fixes inconsistent naming on the context plugins in APEX. All plugins should fillow the naming convention of plugin-A.plugin-A.B.plugin.A.B.C and so on. Not following this convention breaks the APEX documentation build. Issue-ID: POLICY-954 Change-Id: I8aad4a28d143427e60017eaa119ee4f7ce9f5b3d Signed-off-by: liamfallon --- auth/pom.xml | 18 +- packages/apex-pdp-package-full/pom.xml | 20 +- .../context-distribution-hazelcast/pom.xml | 46 --- .../hazelcast/HazelcastContextDistributor.java | 106 ------ .../distribution/hazelcast/package-info.java | 27 -- .../main/resources/hazelcast/hazelcast.xml.sample | 55 --- .../hazelcast/HazelcastContextDistributorTest.java | 74 ---- .../context-distribution-infinispan/pom.xml | 53 --- .../infinispan/InfinispanContextDistributor.java | 115 ------- .../InfinispanDistributorParameters.java | 144 -------- .../distribution/infinispan/InfinispanManager.java | 122 ------- .../distribution/infinispan/package-info.java | 27 -- .../resources/infinispan/infinispan.xml.sample | 40 --- .../InfinispanContextDistributorTest.java | 93 ------ .../plugins-context/context-distribution/pom.xml | 41 --- .../context-locking-curator/pom.xml | 74 ---- .../context/locking/curator/CuratorLockFacade.java | 137 -------- .../locking/curator/CuratorLockManager.java | 187 ----------- .../curator/CuratorLockManagerParameters.java | 120 ------- .../curator/CuratorReentrantReadWriteLock.java | 90 ----- .../context/locking/curator/package-info.java | 27 -- .../context-locking-hazelcast/pom.xml | 59 ---- .../context/locking/hazelcast/HazelcastLock.java | 84 ----- .../locking/hazelcast/HazelcastLockManager.java | 104 ------ .../context/locking/hazelcast/package-info.java | 27 -- plugins/plugins-context/context-locking/pom.xml | 39 --- .../plugins-context/context-persistence/pom.xml | 35 -- .../context-schema/context-schema-avro/pom.xml | 46 --- .../context/schema/avro/AvroArrayObjectMapper.java | 44 --- .../context/schema/avro/AvroBytesObjectMapper.java | 149 --------- .../schema/avro/AvroDirectObjectMapper.java | 165 --------- .../context/schema/avro/AvroEnumObjectMapper.java | 53 --- .../context/schema/avro/AvroNullableMapper.java | 124 ------- .../context/schema/avro/AvroObjectMapper.java | 78 ----- .../schema/avro/AvroObjectMapperFactory.java | 131 -------- .../schema/avro/AvroRecordObjectMapper.java | 43 --- .../context/schema/avro/AvroSchemaHelper.java | 261 --------------- .../schema/avro/AvroSchemaHelperParameters.java | 38 --- .../avro/AvroSchemaKeyTranslationUtilities.java | 140 -------- .../schema/avro/AvroStringObjectMapper.java | 130 -------- .../plugins/context/schema/avro/package-info.java | 27 -- .../context/schema/avro/TestAvroSchemaAAI.java | 76 ----- .../context/schema/avro/TestAvroSchemaArray.java | 107 ------ .../context/schema/avro/TestAvroSchemaEnum.java | 120 ------- .../context/schema/avro/TestAvroSchemaFixed.java | 130 -------- .../avro/TestAvroSchemaHelperBadSchemas.java | 123 ------- .../schema/avro/TestAvroSchemaHelperMarshal.java | 277 --------------- .../schema/avro/TestAvroSchemaHelperUnmarshal.java | 371 --------------------- .../context/schema/avro/TestAvroSchemaMap.java | 135 -------- .../context/schema/avro/TestAvroSchemaRecord.java | 130 -------- .../context/schema/avro/TestAvroSchemaUnion.java | 109 ------ .../context/schema/avro/TestHealthCheckSchema.java | 119 ------- .../avsc/AAIInventoryResponseItemType.avsc | 70 ---- .../test/resources/avsc/ArrayExampleAddress.avsc | 10 - .../src/test/resources/avsc/ArrayExampleLong.avsc | 3 - .../src/test/resources/avsc/EnumSchema.avsc | 5 - .../src/test/resources/avsc/FixedSchema.avsc | 5 - .../test/resources/avsc/HealthCheckBodyType.avsc | 76 ----- .../src/test/resources/avsc/MapExampleAddress.avsc | 10 - .../avsc/MapExampleAddressInvalidFields.avsc | 10 - .../src/test/resources/avsc/MapExampleLong.avsc | 3 - .../src/test/resources/avsc/RecordExample.avsc | 172 ---------- .../resources/avsc/RecordExampleInvalidFields.avsc | 172 ---------- .../src/test/resources/avsc/RecordExampleVPN.avsc | 26 -- .../test/resources/avsc/RecordExampleVPNReuse.avsc | 34 -- .../src/test/resources/avsc/UnionExample.avsc | 30 -- .../test/resources/data/AAIResponse4Policy.json | 20 -- .../src/test/resources/data/AAIResponse4VNF.json | 302 ----------------- .../test/resources/data/AAIResponseExample.json | 209 ------------ .../resources/data/ArrayExampleAddressFull.json | 13 - .../resources/data/ArrayExampleAddressNull.json | 1 - .../test/resources/data/ArrayExampleLongFull.json | 1 - .../test/resources/data/ArrayExampleLongNull.json | 1 - .../src/test/resources/data/EnumExampleBad0.json | 1 - .../src/test/resources/data/EnumExampleBad1.json | 1 - .../src/test/resources/data/EnumExampleHearts.json | 1 - .../src/test/resources/data/EnumExampleNull.json | 1 - .../src/test/resources/data/FixedExampleBad0.json | 1 - .../src/test/resources/data/FixedExampleBad1.json | 1 - .../src/test/resources/data/FixedExampleGood.json | 1 - .../src/test/resources/data/FixedExampleNull.json | 1 - .../src/test/resources/data/HealthCheckEvent.json | 22 -- .../test/resources/data/MapExampleAddressFull.json | 18 - .../data/MapExampleAddressInvalidFields.json | 18 - .../test/resources/data/MapExampleAddressNull.json | 1 - .../test/resources/data/MapExampleLongFull.json | 10 - .../test/resources/data/MapExampleLongNull.json | 1 - .../src/test/resources/data/RecordExampleFull.json | 41 --- .../resources/data/RecordExampleInvalidFields.json | 41 --- .../src/test/resources/data/RecordExampleNull.json | 15 - .../test/resources/data/RecordExampleVPNFull.json | 9 - .../test/resources/data/UnionExampleAllFields.json | 6 - .../test/resources/data/UnionExampleNullField.json | 6 - .../resources/data/UnionExampleOptionalField.json | 5 - .../src/test/resources/logback-test.xml | 74 ---- plugins/plugins-context/context-schema/pom.xml | 38 --- .../plugins-context-distribution-hazelcast/pom.xml | 46 +++ .../hazelcast/HazelcastContextDistributor.java | 106 ++++++ .../distribution/hazelcast/package-info.java | 27 ++ .../main/resources/hazelcast/hazelcast.xml.sample | 55 +++ .../hazelcast/HazelcastContextDistributorTest.java | 74 ++++ .../pom.xml | 53 +++ .../infinispan/InfinispanContextDistributor.java | 115 +++++++ .../InfinispanDistributorParameters.java | 144 ++++++++ .../distribution/infinispan/InfinispanManager.java | 122 +++++++ .../distribution/infinispan/package-info.java | 27 ++ .../resources/infinispan/infinispan.xml.sample | 40 +++ .../InfinispanContextDistributorTest.java | 93 ++++++ .../plugins-context-distribution/pom.xml | 41 +++ .../plugins-context-locking-curator/pom.xml | 74 ++++ .../context/locking/curator/CuratorLockFacade.java | 137 ++++++++ .../locking/curator/CuratorLockManager.java | 187 +++++++++++ .../curator/CuratorLockManagerParameters.java | 120 +++++++ .../curator/CuratorReentrantReadWriteLock.java | 90 +++++ .../context/locking/curator/package-info.java | 27 ++ .../plugins-context-locking-hazelcast/pom.xml | 59 ++++ .../context/locking/hazelcast/HazelcastLock.java | 84 +++++ .../locking/hazelcast/HazelcastLockManager.java | 104 ++++++ .../context/locking/hazelcast/package-info.java | 27 ++ .../plugins-context-locking/pom.xml | 39 +++ .../plugins-context-persistence/pom.xml | 35 ++ .../plugins-context-schema-avro/pom.xml | 46 +++ .../context/schema/avro/AvroArrayObjectMapper.java | 44 +++ .../context/schema/avro/AvroBytesObjectMapper.java | 149 +++++++++ .../schema/avro/AvroDirectObjectMapper.java | 165 +++++++++ .../context/schema/avro/AvroEnumObjectMapper.java | 53 +++ .../context/schema/avro/AvroNullableMapper.java | 124 +++++++ .../context/schema/avro/AvroObjectMapper.java | 78 +++++ .../schema/avro/AvroObjectMapperFactory.java | 131 ++++++++ .../schema/avro/AvroRecordObjectMapper.java | 43 +++ .../context/schema/avro/AvroSchemaHelper.java | 261 +++++++++++++++ .../schema/avro/AvroSchemaHelperParameters.java | 38 +++ .../avro/AvroSchemaKeyTranslationUtilities.java | 140 ++++++++ .../schema/avro/AvroStringObjectMapper.java | 130 ++++++++ .../plugins/context/schema/avro/package-info.java | 27 ++ .../context/schema/avro/TestAvroSchemaAAI.java | 76 +++++ .../context/schema/avro/TestAvroSchemaArray.java | 107 ++++++ .../context/schema/avro/TestAvroSchemaEnum.java | 120 +++++++ .../context/schema/avro/TestAvroSchemaFixed.java | 130 ++++++++ .../avro/TestAvroSchemaHelperBadSchemas.java | 123 +++++++ .../schema/avro/TestAvroSchemaHelperMarshal.java | 277 +++++++++++++++ .../schema/avro/TestAvroSchemaHelperUnmarshal.java | 371 +++++++++++++++++++++ .../context/schema/avro/TestAvroSchemaMap.java | 135 ++++++++ .../context/schema/avro/TestAvroSchemaRecord.java | 130 ++++++++ .../context/schema/avro/TestAvroSchemaUnion.java | 109 ++++++ .../context/schema/avro/TestHealthCheckSchema.java | 119 +++++++ .../avsc/AAIInventoryResponseItemType.avsc | 70 ++++ .../test/resources/avsc/ArrayExampleAddress.avsc | 10 + .../src/test/resources/avsc/ArrayExampleLong.avsc | 3 + .../src/test/resources/avsc/EnumSchema.avsc | 5 + .../src/test/resources/avsc/FixedSchema.avsc | 5 + .../test/resources/avsc/HealthCheckBodyType.avsc | 76 +++++ .../src/test/resources/avsc/MapExampleAddress.avsc | 10 + .../avsc/MapExampleAddressInvalidFields.avsc | 10 + .../src/test/resources/avsc/MapExampleLong.avsc | 3 + .../src/test/resources/avsc/RecordExample.avsc | 172 ++++++++++ .../resources/avsc/RecordExampleInvalidFields.avsc | 172 ++++++++++ .../src/test/resources/avsc/RecordExampleVPN.avsc | 26 ++ .../test/resources/avsc/RecordExampleVPNReuse.avsc | 34 ++ .../src/test/resources/avsc/UnionExample.avsc | 30 ++ .../test/resources/data/AAIResponse4Policy.json | 20 ++ .../src/test/resources/data/AAIResponse4VNF.json | 302 +++++++++++++++++ .../test/resources/data/AAIResponseExample.json | 209 ++++++++++++ .../resources/data/ArrayExampleAddressFull.json | 13 + .../resources/data/ArrayExampleAddressNull.json | 1 + .../test/resources/data/ArrayExampleLongFull.json | 1 + .../test/resources/data/ArrayExampleLongNull.json | 1 + .../src/test/resources/data/EnumExampleBad0.json | 1 + .../src/test/resources/data/EnumExampleBad1.json | 1 + .../src/test/resources/data/EnumExampleHearts.json | 1 + .../src/test/resources/data/EnumExampleNull.json | 1 + .../src/test/resources/data/FixedExampleBad0.json | 1 + .../src/test/resources/data/FixedExampleBad1.json | 1 + .../src/test/resources/data/FixedExampleGood.json | 1 + .../src/test/resources/data/FixedExampleNull.json | 1 + .../src/test/resources/data/HealthCheckEvent.json | 22 ++ .../test/resources/data/MapExampleAddressFull.json | 18 + .../data/MapExampleAddressInvalidFields.json | 18 + .../test/resources/data/MapExampleAddressNull.json | 1 + .../test/resources/data/MapExampleLongFull.json | 10 + .../test/resources/data/MapExampleLongNull.json | 1 + .../src/test/resources/data/RecordExampleFull.json | 41 +++ .../resources/data/RecordExampleInvalidFields.json | 41 +++ .../src/test/resources/data/RecordExampleNull.json | 15 + .../test/resources/data/RecordExampleVPNFull.json | 9 + .../test/resources/data/UnionExampleAllFields.json | 6 + .../test/resources/data/UnionExampleNullField.json | 6 + .../resources/data/UnionExampleOptionalField.json | 5 + .../src/test/resources/logback-test.xml | 74 ++++ .../plugins-context/plugins-context-schema/pom.xml | 38 +++ plugins/plugins-context/pom.xml | 10 +- .../plugins-event-protocol-yaml/pom.xml | 6 - .../integration/integration-context-test/pom.xml | 18 +- .../integration/integration-uservice-test/pom.xml | 8 +- .../performance/performance-benchmark-test/pom.xml | 6 +- .../performance-context-metrics/pom.xml | 18 +- tools/model-generator/pom.xml | 6 +- 197 files changed, 6586 insertions(+), 6600 deletions(-) delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-hazelcast/pom.xml delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/pom.xml delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample delete mode 100644 plugins/plugins-context/context-distribution/context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java delete mode 100644 plugins/plugins-context/context-distribution/pom.xml delete mode 100644 plugins/plugins-context/context-locking/context-locking-curator/pom.xml delete mode 100644 plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-hazelcast/pom.xml delete mode 100644 plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java delete mode 100644 plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java delete mode 100644 plugins/plugins-context/context-locking/pom.xml delete mode 100644 plugins/plugins-context/context-persistence/pom.xml delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/pom.xml delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/EnumSchema.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/FixedSchema.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExample.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/UnionExample.avsc delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4Policy.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4VNF.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponseExample.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad0.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad1.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleHearts.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad0.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad1.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleGood.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/HealthCheckEvent.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressFull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongFull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleFull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleNull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleAllFields.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleNullField.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json delete mode 100644 plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/logback-test.xml delete mode 100644 plugins/plugins-context/context-schema/pom.xml create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample create mode 100644 plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java create mode 100644 plugins/plugins-context/plugins-context-distribution/pom.xml create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/pom.xml create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java create mode 100644 plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java create mode 100644 plugins/plugins-context/plugins-context-locking/pom.xml create mode 100644 plugins/plugins-context/plugins-context-persistence/pom.xml create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/pom.xml create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/EnumSchema.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/FixedSchema.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExample.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/UnionExample.avsc create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4Policy.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4VNF.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponseExample.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad0.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad1.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleHearts.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad0.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad1.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleGood.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/HealthCheckEvent.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressFull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongFull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleFull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleNull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleAllFields.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleNullField.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json create mode 100644 plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/logback-test.xml create mode 100644 plugins/plugins-context/plugins-context-schema/pom.xml diff --git a/auth/pom.xml b/auth/pom.xml index 6fe1f078d..05562509f 100644 --- a/auth/pom.xml +++ b/auth/pom.xml @@ -33,16 +33,8 @@ ${project.artifactId} Policy, state, and task authoring for Apex. - - - apexDefault - - true - - - cli-editor - cli-codegen - - - - \ No newline at end of file + + cli-editor + cli-codegen + + diff --git a/packages/apex-pdp-package-full/pom.xml b/packages/apex-pdp-package-full/pom.xml index 890f9f55e..2b05807e2 100644 --- a/packages/apex-pdp-package-full/pom.xml +++ b/packages/apex-pdp-package-full/pom.xml @@ -43,32 +43,32 @@ - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-hazelcast + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-hazelcast ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-infinispan + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-infinispan ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking-hazelcast + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking-hazelcast ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking-curator + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking-curator ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema-avro + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema + plugins-context-schema-avro ${project.version} diff --git a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/pom.xml b/plugins/plugins-context/context-distribution/context-distribution-hazelcast/pom.xml deleted file mode 100644 index 71806c54f..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution - 2.0.0-SNAPSHOT - - - context-distribution-hazelcast - ${project.artifactId} - [${project.parent.artifactId}] Plugin for distribution using Hazelcast - - - - com.hazelcast - hazelcast - ${version.hazelcast} - - - org.onap.policy.apex-pdp.context - context-test-utils - ${project.version} - test - - - \ No newline at end of file diff --git a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java b/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java deleted file mode 100644 index 2b17b17cf..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.distribution.hazelcast; - -import java.util.Map; - -import org.onap.policy.apex.context.ContextException; -import org.onap.policy.apex.context.impl.distribution.AbstractDistributor; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; - -/** - * This context distributor distributes context across threads in multiple JVMs on multiple hosts. - * It uses hazelcast to distribute maps. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class HazelcastContextDistributor extends AbstractDistributor { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(HazelcastContextDistributor.class); - - // The hazelcast instance for distributing context for this JVM - private static HazelcastInstance hazelcastInstance = null; - - /** - * Create an instance of a Hazelcast Context Distributor. - * - * @throws ContextException On errors creating the context distributor - */ - public HazelcastContextDistributor() throws ContextException { - super(); - LOGGER.entry("HazelcastContextDistributor()"); - - LOGGER.exit("HazelcastContextDistributor()"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.context.impl.distribution.AbstractContextDistributor#init(org.onap. - * policy.apex.model.basicmodel.concepts.AxArtifactKey) - */ - @Override - public void init(final AxArtifactKey key) throws ContextException { - LOGGER.entry("init(" + key + ")"); - - super.init(key); - - // Create the hazelcast instance if it does not already exist - if (hazelcastInstance == null) { - hazelcastInstance = Hazelcast.newHazelcastInstance(); - } - - LOGGER.exit("init(" + key + ")"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.context.impl.distribution.AbstractContextDistributor# - * getContextAlbumMap(org.onap.policy.apex.core.model.concepts.AxArtifactKey) - */ - @Override - public Map getContextAlbumMap(final AxArtifactKey contextAlbumKey) { - // Get the map from Hazelcast - LOGGER.info("HazelcastContextDistributor: create album: " + contextAlbumKey.getID()); - return hazelcastInstance.getMap(contextAlbumKey.getID()); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.context.impl.distribution.AbstractContextDistributor#shutdown() - */ - @Override - public void shutdown() { - // Shut down the hazelcast instance - if (hazelcastInstance != null) { - hazelcastInstance.shutdown(); - } - hazelcastInstance = null; - } -} diff --git a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java b/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java deleted file mode 100644 index 027aeecde..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Implements the Hazelcast context distributor for distribution - * of Apex context across JVMs. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.plugins.context.distribution.hazelcast; diff --git a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample b/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample deleted file mode 100644 index 5f6c1b005..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - ApexHazelcastGroup - ApexHazelcastGroupPassword - - - 5706 - - - 224.2.2.10 - 54327 - - - 127.0.0.1 - - - - - 127.0.0.* - - - - true - slf4j - - false - 60 - - - 16 - - diff --git a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java b/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java deleted file mode 100644 index c999c95f0..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.distribution.hazelcast; - -import java.io.IOException; - -import org.junit.Test; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.test.distribution.ContextAlbumUpdate; -import org.onap.policy.apex.context.test.distribution.ContextInstantiation; -import org.onap.policy.apex.context.test.distribution.ContextUpdate; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -public class HazelcastContextDistributorTest { - private static final String HAZEL_CAST_PLUGIN_CLASS = HazelcastContextDistributor.class.getCanonicalName(); - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(HazelcastContextDistributorTest.class); - - - @Test - public void testContextAlbumUpdateHazelcast() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextAlbumUpdateHazelcast test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS); - new ContextAlbumUpdate().testContextAlbumUpdate(); - - logger.debug("Ran testContextAlbumUpdateHazelcast test"); - } - - @Test - public void testContextInstantiationHazelcast() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextInstantiationHazelcast test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS); - new ContextInstantiation().testContextInstantiation(); - - logger.debug("Ran testContextInstantiationHazelcast test"); - } - - @Test - public void testContextUpdateHazelcast() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextUpdateHazelcast test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS); - new ContextUpdate().testContextUpdate(); - - logger.debug("Ran testContextUpdateHazelcast test"); - } - -} diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/pom.xml b/plugins/plugins-context/context-distribution/context-distribution-infinispan/pom.xml deleted file mode 100644 index c6985a952..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution - 2.0.0-SNAPSHOT - - - context-distribution-infinispan - ${project.artifactId} - [${project.parent.artifactId}] Plugin for distribution using Infinispan - - - - org.infinispan - infinispan-core - 9.2.2.Final - - - org.jboss.slf4j - slf4j-jboss-logging - - - - - org.onap.policy.apex-pdp.context - context-test-utils - ${project.version} - test - - - - \ No newline at end of file diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java deleted file mode 100644 index 9361d0b4c..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.distribution.infinispan; - -import java.util.Map; - -import org.infinispan.Cache; -import org.onap.policy.apex.context.ContextException; -import org.onap.policy.apex.context.impl.distribution.AbstractDistributor; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This context distributor distributes context across threads in multiple JVMs on multiple hosts. - * It uses Infinispan to distribute maps. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class InfinispanContextDistributor extends AbstractDistributor { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(InfinispanContextDistributor.class); - - // The infinispan manager for distributing context for this JVM - private static InfinispanManager infinispanManager = null; - - /** - * Create an instance of an Infinispan Context Distributor. - * - * @throws ContextException On errors creating the context distributor - */ - public InfinispanContextDistributor() throws ContextException { - LOGGER.entry("InfinispanContextDistributor()"); - - LOGGER.exit("InfinispanContextDistributor()"); - } - - /* - * (non-Javadoc) - * - * @see - * com.ericsson.apex.context.impl.distribution.AbstractContextDistributor#init(com.ericsson.apex - * .model.basicmodel.concepts.AxArtifactKey) - */ - @Override - public void init(final AxArtifactKey key) throws ContextException { - LOGGER.entry("init(" + key + ")"); - - super.init(key); - - // Create the infinispan manager if it does not already exist - if (infinispanManager == null) { - // Get the parameters from the parameter service - final InfinispanDistributorParameters parameters = - ParameterService.getParameters(InfinispanDistributorParameters.class); - - LOGGER.debug("initiating Infinispan with the parameters: " + parameters); - - // Create the manager - infinispanManager = new InfinispanManager(parameters); - } - - LOGGER.exit("init(" + key + ")"); - } - - /* - * (non-Javadoc) - * - * @see com.ericsson.apex.core.context.impl.distribution.AbstractContextDistributor# - * getContextAlbumMap(com.ericsson.apex.core.model.concepts.AxArtifactKey) - */ - @Override - public Map getContextAlbumMap(final AxArtifactKey contextAlbumKey) { - LOGGER.info("InfinispanContextDistributor: create album: " + contextAlbumKey.getID()); - - // Get the Cache from Infinispan - final Cache infinispanCache = - infinispanManager.getCacheManager().getCache(contextAlbumKey.getID().replace(':', '_')); - - return infinispanCache; - } - - /* - * (non-Javadoc) - * - * @see com.ericsson.apex.core.context.impl.distribution.AbstractContextDistributor#shutdown() - */ - @Override - public void shutdown() { - // Shut down the infinispan manager - if (infinispanManager != null) { - infinispanManager.shutdown(); - } - infinispanManager = null; - } -} diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java deleted file mode 100644 index d73955224..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.distribution.infinispan; - -import org.onap.policy.apex.context.parameters.DistributorParameters; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; - -/** - * Distributor parameters for the Infinspan Distributor. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class InfinispanDistributorParameters extends DistributorParameters { - // @formatter:off - - /** The default Infinispan configuration file location. */ - public static final String DEFAULT_INFINISPAN_DISTRIBUTION_CONFIG_FILE = "/infinispan/infinispan.xml"; - - /** The default Infinispan jgroups configuration file location. */ - public static final String DEFAULT_INFINISPAN_DISTRIBUTION_JGROUPS_FILE = null; - - /** The default Infinispan IP stack is IPV4. */ - public static final boolean DEFAULT_INFINISPAN_JAVA_NET_PREFER_IPV4_STACK = true; - - /** The default Infinispan bind address is localhost. */ - public static final String DEFAULT_INFINSPAN_JGROUPS_BIND_ADDRESS = "localhost"; - - // Infinspan configuration file names - private String configFile = DEFAULT_INFINISPAN_DISTRIBUTION_CONFIG_FILE; - private String jgroupsFile = DEFAULT_INFINISPAN_DISTRIBUTION_JGROUPS_FILE; - private boolean preferIPv4Stack = DEFAULT_INFINISPAN_JAVA_NET_PREFER_IPV4_STACK; - private String jGroupsBindAddress = DEFAULT_INFINSPAN_JGROUPS_BIND_ADDRESS; - // @formatter:on - - /** - * The Constructor. - */ - public InfinispanDistributorParameters() { - super(InfinispanDistributorParameters.class.getCanonicalName()); - ParameterService.registerParameters(InfinispanDistributorParameters.class, this); - ParameterService.registerParameters(DistributorParameters.class, this); - } - - /** - * Gets the config file. - * - * @return the config file - */ - public String getConfigFile() { - return configFile; - } - - /** - * Sets the config file. - * - * @param configFile the config file - */ - public void setConfigFile(final String configFile) { - this.configFile = configFile; - } - - /** - * Gets the jgroups file. - * - * @return the jgroups file - */ - public String getJgroupsFile() { - return jgroupsFile; - } - - /** - * Sets the jgroups file. - * - * @param jgroupsFile the jgroups file - */ - public void setJgroupsFile(final String jgroupsFile) { - this.jgroupsFile = jgroupsFile; - } - - /** - * Prefer I pv 4 stack. - * - * @return true, if prefer I pv 4 stack - */ - public boolean preferIPv4Stack() { - return preferIPv4Stack; - } - - /** - * Sets the prefer I pv 4 stack. - * - * @param preferIPv4Stack the prefer I pv 4 stack - */ - public void setPreferIPv4Stack(final boolean preferIPv4Stack) { - this.preferIPv4Stack = preferIPv4Stack; - } - - /** - * Getj groups bind address. - * - * @return the j groups bind address - */ - public String getjGroupsBindAddress() { - return jGroupsBindAddress; - } - - /** - * Setj groups bind address. - * - * @param jGroupsBindAddress the j groups bind address - */ - public void setjGroupsBindAddress(final String jGroupsBindAddress) { - this.jGroupsBindAddress = jGroupsBindAddress; - } - - /* - * (non-Javadoc) - * - * @see com.ericsson.apex.context.parameters.DistributorParameters#toString() - */ - @Override - public String toString() { - return "InfinispanDistributorParameters [configFile=" + configFile + ", jgroupsFile=" + jgroupsFile - + ", preferIPv4Stack=" + preferIPv4Stack + ", jGroupsBindAddress=" + jGroupsBindAddress + "]"; - } -} diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java deleted file mode 100644 index 1a2076f10..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.distribution.infinispan; - -import java.io.IOException; - -import org.infinispan.manager.DefaultCacheManager; -import org.infinispan.manager.EmbeddedCacheManager; -import org.onap.policy.apex.context.ContextException; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class InfinispanManager holds the Infinispan cache manager for a JVM. - */ -public class InfinispanManager { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(InfinispanManager.class); - - // The Infinispan Cache Manager - private EmbeddedCacheManager cacheManager; - - /** - * Constructor, set up an Infinispan cache manager. - * - * @param infinispanDistributorParameters the infinispan distributor parameters - * @throws ContextException On errors connecting to Infinispan - */ - public InfinispanManager(final InfinispanDistributorParameters infinispanDistributorParameters) - throws ContextException { - LOGGER.entry("Creating Infinispan Manager: " + infinispanDistributorParameters); - - setSystemProperties(infinispanDistributorParameters); - - try { - LOGGER.debug("starting infinispan cache manager using specified configuration . . ."); - cacheManager = new DefaultCacheManager(infinispanDistributorParameters.getConfigFile()); - LOGGER.debug("started infinispan cache manager using specified configuration"); - } catch (final IOException ioException) { - final String errorMessage = - "failed to start infinispan cache manager, no infinispan configuration found on local file system or in classpath, " - + "try setting Infinspan \"configFile\" parameter"; - LOGGER.error(errorMessage); - throw new ContextException(errorMessage, ioException); - } catch (final Exception e) { - LOGGER.error("failed to start infinispan cache manager using specified configuration", e); - throw new ContextException("failed to start infinispan cache manager using specified configuration", e); - } - - // Start the cache manager - cacheManager.start(); - - Runtime.getRuntime().addShutdownHook(new InfinspanManagerShutdownHook()); - - LOGGER.exit("Created Infinispan Manager: " + infinispanDistributorParameters); - } - - /** - * Shutdown the manager. - */ - public void shutdown() { - if (cacheManager == null) { - return; - } - - cacheManager.stop(); - cacheManager = null; - } - - /** - * Get the cache manager. - * - * @return the infinispan cache manager - */ - public EmbeddedCacheManager getCacheManager() { - return cacheManager; - } - - /** - * Set system properties used by Infinispan. - * - * @param infinispanDistributorParameters The parameter values to set are passed as properties - */ - private void setSystemProperties(final InfinispanDistributorParameters infinispanDistributorParameters) { - System.setProperty("java.net.preferIPv4Stack", - Boolean.toString(infinispanDistributorParameters.preferIPv4Stack())); - System.setProperty("jgroups.bind_addr", infinispanDistributorParameters.getjGroupsBindAddress()); - } - - /** - * Private class to implement the shutdown hook for this infinispan manager. - */ - public class InfinspanManagerShutdownHook extends Thread { - /* - * (non-Javadoc) - * - * @see java.lang.Thread#run() - */ - @Override - public void run() { - shutdown(); - } - } -} diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java deleted file mode 100644 index b9ceeb668..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Implements the Infinispan context distributor for - * distribution of APEX context across JVMs. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.plugins.context.distribution.infinispan; diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample deleted file mode 100644 index 302eac935..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java deleted file mode 100644 index 34fa7d439..000000000 --- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.policy.apex.plugins.context.distribution.infinispan; - -import java.io.IOException; - -import org.junit.Test; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.test.distribution.ContextAlbumUpdate; -import org.onap.policy.apex.context.test.distribution.ContextInstantiation; -import org.onap.policy.apex.context.test.distribution.ContextUpdate; -import org.onap.policy.apex.context.test.distribution.SequentialContextInstantiation; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -public class InfinispanContextDistributorTest { - private static final XLogger logger = XLoggerFactory.getXLogger(InfinispanContextDistributorTest.class); - - private static final String PLUGIN_CLASS = InfinispanContextDistributor.class.getCanonicalName(); - - @Test - public void testContextAlbumUpdateInfinispan() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextAlbumUpdateInfinispan test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); - new InfinispanDistributorParameters(); - - new ContextAlbumUpdate().testContextAlbumUpdate(); - - logger.debug("Ran testContextAlbumUpdateInfinispan test"); - } - - @Test - public void testContextInstantiationInfinispan() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextInstantiationInfinispan test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); - new InfinispanDistributorParameters(); - - new ContextInstantiation().testContextInstantiation(); - - logger.debug("Ran testContextInstantiationInfinispan test"); - } - - @Test - public void testContextUpdateInfinispan() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextUpdateInfinispan test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); - new InfinispanDistributorParameters(); - - new ContextUpdate().testContextUpdate(); - - logger.debug("Ran testContextUpdateInfinispan test"); - } - - @Test - public void testSequentialContextInstantiationInfinispan() throws ApexModelException, IOException, ApexException { - logger.debug("Running testSequentialContextInstantiationInfinispan test . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); - new InfinispanDistributorParameters(); - - new SequentialContextInstantiation().testSequentialContextInstantiation(); - - logger.debug("Ran testSequentialContextInstantiationInfinispan test"); - } - - -} diff --git a/plugins/plugins-context/context-distribution/pom.xml b/plugins/plugins-context/context-distribution/pom.xml deleted file mode 100644 index 94e769151..000000000 --- a/plugins/plugins-context/context-distribution/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context - plugins-context - 2.0.0-SNAPSHOT - - - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution - pom - - ${project.artifactId} - Plugins for 3pps that distribute context - - - context-distribution-hazelcast - context-distribution-infinispan - - \ No newline at end of file diff --git a/plugins/plugins-context/context-locking/context-locking-curator/pom.xml b/plugins/plugins-context/context-locking/context-locking-curator/pom.xml deleted file mode 100644 index 220bfbae6..000000000 --- a/plugins/plugins-context/context-locking/context-locking-curator/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking - 2.0.0-SNAPSHOT - - - context-locking-curator - ${project.artifactId} - [${project.parent.artifactId}] Plugin for locking using Curator - - - - org.apache.curator - curator-framework - 4.0.1 - - - - org.apache.zookeeper - zookeeper - - - - - org.apache.curator - curator-recipes - 4.0.1 - - - - org.apache.zookeeper - zookeeper - 3.5.4-beta - - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - - - - org.apache.curator - curator-recipes - 4.0.1 - - - diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java deleted file mode 100644 index 928255031..000000000 --- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.locking.curator; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; - -import org.apache.curator.framework.recipes.locks.InterProcessMutex; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class provides a facade over the {@link Lock} interface for Curator locks. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class CuratorLockFacade implements Lock { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(CuratorLockFacade.class); - - // The Lock ID - private final String lockId; - - // The mutex used for Curator locking - private final InterProcessMutex lockMutex; - - /** - * Create the lock Facade. - * - * @param lockMutex The lock mutex behind the facade - * @param lockId The ID of the lock - */ - public CuratorLockFacade(final InterProcessMutex lockMutex, final String lockId) { - this.lockId = lockId; - this.lockMutex = lockMutex; - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.Lock#lock() - */ - @Override - public void lock() { - try { - lockMutex.acquire(); - } catch (final Exception e) { - LOGGER.warn("failed to acquire lock for \"" + lockId, e); - } - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.Lock#lockInterruptibly() - */ - @Override - public void lockInterruptibly() throws InterruptedException { - LOGGER.warn("lockInterruptibly() not supported for \"" + lockId); - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.Lock#tryLock() - */ - @Override - public boolean tryLock() { - try { - lockMutex.acquire(); - return true; - } catch (final Exception e) { - LOGGER.warn("failed to acquire lock for \"" + lockId, e); - return false; - } - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.Lock#tryLock(long, java.util.concurrent.TimeUnit) - */ - @Override - public boolean tryLock(final long time, final TimeUnit unit) throws InterruptedException { - try { - lockMutex.acquire(time, unit); - return true; - } catch (final Exception e) { - LOGGER.warn("failed to acquire lock for \"" + lockId, e); - return false; - } - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.Lock#unlock() - */ - @Override - public void unlock() { - try { - lockMutex.release(); - } catch (final Exception e) { - LOGGER.warn("failed to release lock for \"" + lockId, e); - } - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.Lock#newCondition() - */ - @Override - public Condition newCondition() { - LOGGER.warn("newCondition() not supported for \"" + lockId); - return null; - } -} diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java deleted file mode 100644 index 477a010fa..000000000 --- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.locking.curator; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReadWriteLock; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.framework.state.ConnectionState; -import org.apache.curator.framework.state.ConnectionStateListener; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.utils.CloseableUtils; -import org.apache.zookeeper.CreateMode; -import org.onap.policy.apex.context.ContextException; -import org.onap.policy.apex.context.impl.locking.AbstractLockManager; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class CuratorLockManager manages the Curator interface towards Zookeeper for administering - * the Apex Context Album instance locks.. - */ -public class CuratorLockManager extends AbstractLockManager { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(CuratorLockManager.class); - - // The Curator framework used for locking - private CuratorFramework curatorFramework; - - // The address of the Zookeeper server - private String curatorZookeeperAddress; - - /** - * Constructor, set up a lock manager that uses Curator locking. - * - * @throws ContextException On errors connecting to Curator - */ - public CuratorLockManager() throws ContextException { - LOGGER.entry("CuratorLockManager(): setting up the Curator lock manager . . ."); - - LOGGER.exit("CuratorLockManager(): Curator lock manager set up"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.context.impl.locking.AbstractLockManager#init(org.onap.policy.apex. - * model. basicmodel.concepts.AxArtifactKey) - */ - @Override - public void init(final AxArtifactKey key) throws ContextException { - LOGGER.entry("init(" + key + ")"); - - super.init(key); - - // Get the lock manager parameters - final CuratorLockManagerParameters lockParameters = - ParameterService.getParameters(CuratorLockManagerParameters.class); - - // Check if the curator address has been set - curatorZookeeperAddress = lockParameters.getZookeeperAddress(); - if (curatorZookeeperAddress == null || curatorZookeeperAddress.trim().length() == 0) { - LOGGER.warn( - "could not set up Curator locking, check if the curator Zookeeper address parameter is set correctly"); - throw new ContextException( - "could not set up Curator locking, check if the curator Zookeeper address parameter is set correctly"); - } - - // Set up the curator framework we'll use - curatorFramework = CuratorFrameworkFactory.builder().connectString(curatorZookeeperAddress) - .retryPolicy(new ExponentialBackoffRetry(lockParameters.getZookeeperConnectSleepTime(), - lockParameters.getZookeeperContextRetries())) - .build(); - - // Listen for changes on the Curator connection - curatorFramework.getConnectionStateListenable().addListener(new CuratorManagerConnectionStateListener()); - - // Start the framework and specify Ephemeral nodes - curatorFramework.start(); - - // Wait for the connection to be made - try { - curatorFramework.blockUntilConnected( - lockParameters.getZookeeperConnectSleepTime() * lockParameters.getZookeeperContextRetries(), - TimeUnit.MILLISECONDS); - } catch (final InterruptedException e) { - // restore the interrupt status - Thread.currentThread().interrupt(); - LOGGER.warn("could not connect to Zookeeper server at \"" + curatorZookeeperAddress - + "\", wait for connection timed out"); - throw new ContextException("could not connect to Zookeeper server at \"" + curatorZookeeperAddress - + "\", wait for connection timed out"); - } - - if (!curatorFramework.getZookeeperClient().isConnected()) { - LOGGER.warn("could not connect to Zookeeper server at \"" + curatorZookeeperAddress - + "\", see error log for details"); - throw new ContextException("could not connect to Zookeeper server at \"" + curatorZookeeperAddress - + "\", see error log for details"); - } - - // We'll use Ephemeral nodes for locks on the Zookeeper server - curatorFramework.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL); - - LOGGER.exit("init(" + key + "," + lockParameters + ")"); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.context.impl.locking.AbstractLockManager#getReentrantReadWriteLock( - * java.lang.String) - */ - @Override - public ReadWriteLock getReentrantReadWriteLock(final String lockId) throws ContextException { - // Check if the framework is active - if (curatorFramework != null && curatorFramework.getZookeeperClient().isConnected()) { - return new CuratorReentrantReadWriteLock(curatorFramework, "/" + lockId); - } else { - throw new ContextException("creation of lock using Zookeeper server at \"" + curatorZookeeperAddress - + "\", failed, see error log for details"); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.context.LockManager#shutdown() - */ - @Override - public void shutdown() { - if (curatorFramework == null) { - return; - } - CloseableUtils.closeQuietly(curatorFramework); - curatorFramework = null; - } - - /** - * This class is a callback class for state changes on the curator to Zookeeper connection. - */ - private class CuratorManagerConnectionStateListener implements ConnectionStateListener { - - /* - * (non-Javadoc) - * - * @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache. - * curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState) - */ - @Override - public void stateChanged(final CuratorFramework incomngCuratorFramework, final ConnectionState newState) { - // Is the state changed for this curator framework? - if (!incomngCuratorFramework.equals(curatorFramework)) { - return; - } - - LOGGER.info("curator state of client \"" + curatorFramework + "\" connected to \"" + curatorZookeeperAddress - + "\" changed to " + newState); - - if (newState != ConnectionState.CONNECTED) { - shutdown(); - } - } - } -} diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java deleted file mode 100644 index 9e8d5d2af..000000000 --- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.locking.curator; - -import org.onap.policy.apex.context.parameters.LockManagerParameters; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; - -/** - * Bean class for Curator locking parameters. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class CuratorLockManagerParameters extends LockManagerParameters { - // @formatter:off - /** The default address used to connect to the Zookeeper server. */ - public static final String DEFAULT_ZOOKEEPER_ADDRESS = "localhost:2181"; - - /** The default sleep time to use when connecting to the Zookeeper server. */ - public static final int DEFAULT_ZOOKEEPER_CONNECT_SLEEP_TIME = 1000; - - /** The default number of times to retry failed connections to the Zookeeper server. */ - public static final int DEFAULT_ZOOKEEPER_CONNECT_RETRIES = 3; - - // Curator parameters - private String zookeeperAddress = DEFAULT_ZOOKEEPER_ADDRESS; - private int zookeeperConnectSleepTime = DEFAULT_ZOOKEEPER_CONNECT_SLEEP_TIME; - private int zookeeperContextRetries = DEFAULT_ZOOKEEPER_CONNECT_RETRIES; - // @formatter:on - - /** - * The Constructor. - */ - public CuratorLockManagerParameters() { - super(CuratorLockManagerParameters.class.getCanonicalName()); - ParameterService.registerParameters(CuratorLockManagerParameters.class, this); - } - - /** - * Gets the zookeeper address. - * - * @return the zookeeper address - */ - public String getZookeeperAddress() { - return zookeeperAddress; - } - - /** - * Sets the zookeeper address. - * - * @param zookeeperAddress the zookeeper address - */ - public void setZookeeperAddress(final String zookeeperAddress) { - this.zookeeperAddress = zookeeperAddress; - } - - /** - * Gets the zookeeper connect sleep time. - * - * @return the zookeeper connect sleep time - */ - public int getZookeeperConnectSleepTime() { - return zookeeperConnectSleepTime; - } - - /** - * Sets the zookeeper connect sleep time. - * - * @param zookeeperConnectSleepTime the zookeeper connect sleep time - */ - public void setZookeeperConnectSleepTime(final int zookeeperConnectSleepTime) { - this.zookeeperConnectSleepTime = zookeeperConnectSleepTime; - } - - /** - * Gets the zookeeper context retries. - * - * @return the zookeeper context retries - */ - public int getZookeeperContextRetries() { - return zookeeperContextRetries; - } - - /** - * Sets the zookeeper context retries. - * - * @param zookeeperContextRetries the zookeeper context retries - */ - public void setZookeeperContextRetries(final int zookeeperContextRetries) { - this.zookeeperContextRetries = zookeeperContextRetries; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.context.parameters.LockManagerParameters#toString() - */ - @Override - public String toString() { - return "CuratorLockManagerParameters [zookeeperAddress=" + zookeeperAddress + ", zookeeperConnectSleepTime=" - + zookeeperConnectSleepTime + ", zookeeperContextRetries=" + zookeeperContextRetries + "]"; - } -} diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java deleted file mode 100644 index 22bf5e596..000000000 --- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.locking.curator; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock; - -/** - * This class maps a Curator {@link InterProcessReadWriteLock} to a Java {@link ReadWriteLock}. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class CuratorReentrantReadWriteLock implements ReadWriteLock { - // The Lock ID - private final String lockID; - - // The Curator lock - private final InterProcessReadWriteLock curatorReadWriteLock; - - // The Curator Lock facades for read and write locks - private final CuratorLockFacade readLockFacade; - private final CuratorLockFacade writeLockFacade; - - /** - * Create a Curator lock. - * - * @param curatorFramework the Curator framework to use to create the lock - * @param lockId The unique ID of the lock. - */ - public CuratorReentrantReadWriteLock(final CuratorFramework curatorFramework, final String lockId) { - lockID = lockId; - - // Create the Curator lock - curatorReadWriteLock = new InterProcessReadWriteLock(curatorFramework, lockId); - - // Create the lock facades - readLockFacade = new CuratorLockFacade(curatorReadWriteLock.readLock(), lockId); - writeLockFacade = new CuratorLockFacade(curatorReadWriteLock.writeLock(), lockId); - } - - /** - * Get the lock Id of the lock. - * - * @return the lock ID - */ - public String getLockID() { - return lockID; - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.ReadWriteLock#readLock() - */ - @Override - public Lock readLock() { - return readLockFacade; - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.ReadWriteLock#writeLock() - */ - @Override - public Lock writeLock() { - return writeLockFacade; - } -} diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java deleted file mode 100644 index d867c396a..000000000 --- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Implements locking on context items in APEX context albums using - * Curator centralized locking. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.plugins.context.locking.curator; diff --git a/plugins/plugins-context/context-locking/context-locking-hazelcast/pom.xml b/plugins/plugins-context/context-locking/context-locking-hazelcast/pom.xml deleted file mode 100644 index 3e581ecad..000000000 --- a/plugins/plugins-context/context-locking/context-locking-hazelcast/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking - 2.0.0-SNAPSHOT - - - context-locking-hazelcast - ${project.artifactId} - [${project.parent.artifactId}] Plugin for locking using Hazelcast - - - - com.hazelcast - hazelcast - ${version.hazelcast} - - - org.onap.policy.apex-pdp.core - core-infrastructure - ${project.version} - test - - - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-hazelcast - ${project.version} - test - - - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-infinispan - ${project.version} - test - - - \ No newline at end of file diff --git a/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java b/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java deleted file mode 100644 index 73678ad2a..000000000 --- a/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.locking.hazelcast; - -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; - -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.ILock; - -/** - * This class maps a Hazelcast {@link ILock} to a Java {@link ReadWriteLock}. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class HazelcastLock implements ReadWriteLock { - // The Lock ID - private final String lockID; - - // The hazelcast lock - private final ILock readLock; - private final ILock writeLock; - - /** - * Create a Hazelcast lock. - * - * @param hazelcastInstance the hazelcast instance to use to create the lock - * @param lockId The unique ID of the lock. - */ - public HazelcastLock(final HazelcastInstance hazelcastInstance, final String lockId) { - lockID = lockId; - - // Create the Hazelcast read and write locks - readLock = hazelcastInstance.getLock(lockId + "_READ"); - writeLock = hazelcastInstance.getLock(lockId + "_WRITE"); - } - - /** - * Get the lock Id of the lock. - * - * @return the lock ID - */ - public String getLockID() { - return lockID; - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.ReadWriteLock#readLock() - */ - @Override - public Lock readLock() { - return readLock; - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.locks.ReadWriteLock#writeLock() - */ - @Override - public Lock writeLock() { - return writeLock; - } -} diff --git a/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java b/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java deleted file mode 100644 index 34258bf24..000000000 --- a/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.locking.hazelcast; - -import java.util.concurrent.locks.ReadWriteLock; - -import org.onap.policy.apex.context.ContextException; -import org.onap.policy.apex.context.impl.locking.AbstractLockManager; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; - -/** - * The Class HazelcastLockManager manages Hazelcast locks for locks on items in Apex context albums. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class HazelcastLockManager extends AbstractLockManager { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(HazelcastLockManager.class); - - private HazelcastInstance hazelcastInstance; - - /** - * Constructor, set up a lock manager that uses Hazelcast locking. - * - * @throws ContextException On errors connecting to the Hazelcast cluster - */ - public HazelcastLockManager() throws ContextException { - LOGGER.entry("HazelcastLockManager(): setting up the Hazelcast lock manager . . ."); - - LOGGER.exit("HazelcastLockManager(): Hazelcast lock manager set up"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.context.impl.locking.AbstractLockManager#init(org.onap.policy.apex. - * model. basicmodel.concepts.AxArtifactKey) - */ - @Override - public void init(final AxArtifactKey key) throws ContextException { - LOGGER.entry("init(" + key + ")"); - - super.init(key); - - // Set up the Hazelcast instance for lock handling - hazelcastInstance = Hazelcast.newHazelcastInstance(); - - LOGGER.exit("init(" + key + ")"); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.context.impl.locking.AbstractLockManager#getReentrantReadWriteLock( - * java.lang.String) - */ - @Override - public ReadWriteLock getReentrantReadWriteLock(final String lockId) throws ContextException { - // Check if the framework is active - if (hazelcastInstance != null && hazelcastInstance.getLifecycleService().isRunning()) { - return new HazelcastLock(hazelcastInstance, lockId); - } else { - throw new ContextException("creation of hazelcast lock failed, see error log for details"); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.context.LockManager#shutdown() - */ - @Override - public void shutdown() { - if (hazelcastInstance == null) { - return; - } - hazelcastInstance.shutdown(); - hazelcastInstance = null; - } -} diff --git a/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java b/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java deleted file mode 100644 index 8d35556c4..000000000 --- a/plugins/plugins-context/context-locking/context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Implements locking on context items in APEX context albums using - * Hazelcast distributed locking. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.plugins.context.locking.hazelcast; diff --git a/plugins/plugins-context/context-locking/pom.xml b/plugins/plugins-context/context-locking/pom.xml deleted file mode 100644 index a25eb927d..000000000 --- a/plugins/plugins-context/context-locking/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context - plugins-context - 2.0.0-SNAPSHOT - - - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking - pom - ${project.artifactId} - - Plugins for 3pps that lock context - - context-locking-curator - context-locking-hazelcast - - \ No newline at end of file diff --git a/plugins/plugins-context/context-persistence/pom.xml b/plugins/plugins-context/context-persistence/pom.xml deleted file mode 100644 index ae56b887c..000000000 --- a/plugins/plugins-context/context-persistence/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context - plugins-context - 2.0.0-SNAPSHOT - - - org.onap.policy.apex-pdp.plugins.plugins-context.context-persistence - context-persistence - pom - - ${project.artifactId} - Plugins for 3pps that persist context - \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/pom.xml b/plugins/plugins-context/context-schema/context-schema-avro/pom.xml deleted file mode 100644 index 37268676b..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema - 2.0.0-SNAPSHOT - - - context-schema-avro - ${project.artifactId} - [${project.parent.artifactId}] Plugin for schemas using Avro - - - - org.apache.avro - avro - 1.8.2 - - - org.onap.policy.apex-pdp.model - policy-model - ${project.version} - test - - - \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java deleted file mode 100644 index 56d84251f..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericData.Array; - -/** - * Object mapper for arrays, uses default behaviour except for a specific default constructor - * implementation. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroArrayObjectMapper extends AvroDirectObjectMapper { - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. - * apache.avro.Schema) - */ - @SuppressWarnings("rawtypes") - @Override - public Object createNewInstance(final Schema avroSchema) { - return new Array(0, avroSchema); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java deleted file mode 100644 index dc281a52b..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import java.nio.ByteBuffer; - -import org.apache.avro.Schema; -import org.apache.avro.Schema.Type; -import org.onap.policy.apex.context.ContextRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class does string mapping from the Avro BYTES type to a Java byte array. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroBytesObjectMapper implements AvroObjectMapper { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroBytesObjectMapper.class); - - // The user keyAvro type for direct mapping - private AxKey userKey; - private Type avroType; - - // The Apex compatible class - private final Class schemaClass = Byte[].class; - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getJavaClass() - */ - @Override - public Class getJavaClass() { - return schemaClass; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#setAvroType(org.apache. - * avro. Schema.Type) - */ - @Override - public void init(final AxKey intUserKey, final Type initAvroType) { - this.userKey = intUserKey; - this.avroType = initAvroType; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. - * apache. avro.Schema) - */ - @Override - public Object createNewInstance(final Schema avroSchema) { - // By default, we do not create an instance, normal Java object creation for byte arrays is - // sufficient - return null; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getAvroType() - */ - @Override - public Type getAvroType() { - return avroType; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapFromAvro(java.lang. - * Object) - */ - @Override - public Object mapFromAvro(final Object avroObject) { - // The Avro object should be a Utf8 object - if (!(avroObject instanceof ByteBuffer)) { - final String returnString = - userKey.getID() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass() - + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - - // Cast the byte buffer object so we get access to its methods - final ByteBuffer byteBufferAvroObject = (ByteBuffer) avroObject; - - // read the byte buffer into a byte array - final byte[] byteArray = new byte[byteBufferAvroObject.remaining()]; - byteBufferAvroObject.get(byteArray); - - return byteArray; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapToAvro(java.lang.Object) - */ - @Override - public Object mapToAvro(final Object object) { - if (object == null) { - final String returnString = userKey.getID() + ": cannot encode a null object of class \"" - + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - - // The incoming object should be a byte array - if (!(object instanceof byte[])) { - final String returnString = userKey.getID() + ": object \"" + object + "\" of class \"" + object.getClass() - + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - - // Create a ByteBuffer object to serialize the bytes - final ByteBuffer byteBuffer = ByteBuffer.wrap((byte[]) object); - - return byteBuffer; - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java deleted file mode 100644 index acf64c3c9..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.avro.Schema; -import org.apache.avro.Schema.Type; -import org.apache.avro.generic.GenericData; -import org.onap.policy.apex.context.ContextRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class does direct mapping from Avro classes to Java classes, used for Avro primitive types - * that directly produce Java objects. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroDirectObjectMapper implements AvroObjectMapper { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroDirectObjectMapper.class); - - // Map for Avro primitive types to Java primitive types - private static final Map> AVRO_JAVA_TYPE_MAP = new TreeMap<>(); - - // @formatter:off - // Initialize the mapping - static { - AVRO_JAVA_TYPE_MAP.put(Schema.Type.ARRAY, GenericData.Array.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.BOOLEAN, Boolean.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.DOUBLE, Double.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.ENUM, GenericData.EnumSymbol.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.FIXED, GenericData.Fixed.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.FLOAT, Float.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.INT, Integer.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.LONG, Long.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.MAP, HashMap.class); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.NULL, null); - AVRO_JAVA_TYPE_MAP.put(Schema.Type.RECORD, GenericData.Record.class); - } - // @formatter:on - - // The user keyAvro type for direct mapping - private AxKey userKey; - private Type avroType; - - // The Apex compatible class - private Class schemaClass; - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getJavaClass() - */ - @Override - public Class getJavaClass() { - return schemaClass; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#setAvroType(org.apache. - * avro. Schema.Type) - */ - @Override - public void init(final AxKey initUserKey, final Type initAvroType) { - this.userKey = initUserKey; - this.avroType = initAvroType; - schemaClass = AVRO_JAVA_TYPE_MAP.get(avroType); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. - * apache. avro.Schema) - */ - @Override - public Object createNewInstance(final Schema avroSchema) { - // By default, we do not create an instance, normal Java object creation is sufficient - return null; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getAvroType() - */ - @Override - public Type getAvroType() { - return avroType; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapFromAvro(java.lang. - * Object) - */ - @Override - public Object mapFromAvro(final Object avroObject) { - // Always return null if the schema is a null schema - if (schemaClass == null) { - return null; - } - - // It is legal for the schema class to be null, if the Avro schema has a "null" type then - // the decoded object is always returned as a null - if (!schemaClass.isAssignableFrom(avroObject.getClass())) { - final String returnString = - userKey.getID() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass() - + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - - return avroObject; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapToAvro(java.lang.Object) - */ - @Override - public Object mapToAvro(final Object object) { - // Null values are only allowed if the schema class is null - if (object == null) { - if (schemaClass != null) { - final String returnString = userKey.getID() + ": cannot encode a null object of class \"" - + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - } - - // For direct mappings, just work directly with the Java objects - return object; - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java deleted file mode 100644 index ec84450d5..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import java.util.List; - -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericData.EnumSymbol; - -/** - * Object mapper for enums, uses default behaviour except for a specific default constructor - * implementation. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroEnumObjectMapper extends AvroDirectObjectMapper { - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. - * apache.avro.Schema) - */ - @Override - public Object createNewInstance(final Schema avroSchema) { - // Initialize the ENUM to the first ENUM symbol on the list - final List enumSymbols = avroSchema.getEnumSymbols(); - - // Check if any ENUM symbols have been defined - if (enumSymbols == null || enumSymbols.isEmpty()) { - return null; - } - - return new EnumSymbol(avroSchema, enumSymbols.get(0)); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java deleted file mode 100644 index ff8806c86..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import org.apache.avro.Schema; -import org.apache.avro.Schema.Type; - -import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; - -/** - * The Class AvroNullableMapper handles Avro null mappings to Java null values. - * - * @author John Keeney (john.keeney@ericsson.com) - */ -public class AvroNullableMapper extends AvroDirectObjectMapper { - // The wrapped mapper for nullables - private final AvroObjectMapper wrappedMapper; - - /** - * The Constructor. - * - * @param wrappedMapper the wrapped mapper - */ - public AvroNullableMapper(final AvroObjectMapper wrappedMapper) { - this.wrappedMapper = wrappedMapper; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#getJavaClass() - */ - @Override - public Class getJavaClass() { - return wrappedMapper.getJavaClass(); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#init(org.onap.policy. - * apex. model.basicmodel.concepts.AxKey, org.apache.avro.Schema.Type) - */ - @Override - public void init(final AxKey userKey, final Type avroType) { - wrappedMapper.init(userKey, avroType); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#createNewInstance( - * org. apache.avro.Schema) - */ - @Override - public Object createNewInstance(final Schema avroSchema) { - return wrappedMapper.createNewInstance(avroSchema); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#getAvroType() - */ - @Override - public Type getAvroType() { - return Schema.Type.UNION; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#mapFromAvro(java. - * lang. Object) - */ - @Override - public Object mapFromAvro(final Object avroObject) { - if (avroObject == null) { - return null; - } else { - return wrappedMapper.mapFromAvro(avroObject); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#mapToAvro(java.lang. - * Object) - */ - @Override - public Object mapToAvro(final Object object) { - if (object == null) { - return null; - } else { - throw new ApexRuntimeException("Unions/Nullable is not supported in output event ... Coming soon!"); - } - - } - -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java deleted file mode 100644 index 77de5928e..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import org.apache.avro.Schema; -import org.apache.avro.Schema.Type; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; - -/** - * This interface is used to allow mapping of Avro object to and from Java objects. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public interface AvroObjectMapper { - /** - * Get the Java class produced and consumed by this mapper. - * - * @return the Java class - */ - Class getJavaClass(); - - /** - * Initialize the mapper is working with. - * - * @param userKey the user key - * @param avroType the avro type - */ - void init(AxKey userKey, Type avroType); - - /** - * Create a new instance of the java object the Avro schema maps to. - * - * @param avroSchema the Avro schema to use to create the new instance - * @return a new instance of the object - */ - Object createNewInstance(Schema avroSchema); - - /** - * Set the Avro type the mapper is working with. - * - * @return the avro type - */ - Type getAvroType(); - - /** - * Map the Avro object to an object Apex can handler. - * - * @param avroObject the Avro object to map - * @return the Apex-compatible object - */ - Object mapFromAvro(Object avroObject); - - /** - * Map the Apex object to an Avro object. - * - * @param object the Apex-compatible object - * @return the Avro object - */ - Object mapToAvro(Object object); -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java deleted file mode 100644 index 22152a8da..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.avro.Schema; -import org.onap.policy.apex.context.ContextRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class maps between Avro types to Java types. This class is thread safe. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroObjectMapperFactory { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroObjectMapperFactory.class); - - // Map for Avro primitive types to Java primitive types - private static final Map> AVRO_OBJECT_MAPPER_MAP = new TreeMap<>(); - - // @formatter:off - // Initialize the mapping - static { - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.ARRAY, AvroArrayObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.BOOLEAN, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.BYTES, AvroBytesObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.DOUBLE, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.ENUM, AvroEnumObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.FIXED, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.FLOAT, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.INT, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.LONG, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.MAP, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.NULL, AvroDirectObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.RECORD, AvroRecordObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.STRING, AvroStringObjectMapper.class); - AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.UNION, null); - } - // @formatter:on - - /** - * Gets the Avro object mapper to use for an artifact with the given key and schema. - * - * @param userKey the key of the artifact - * @param incomingSchema the incoming schema - * @return the avro object mapper - */ - public AvroObjectMapper get(final AxKey userKey, final Schema incomingSchema) { - Schema schema = incomingSchema; - boolean isnullable = false; - if (Schema.Type.UNION.equals(schema.getType())) { - - final List types = schema.getTypes(); - // TODO: properly support UNIONS - // currently only support unions with 2 types, one of which is NULL - final Schema nullschema = Schema.create(Schema.Type.NULL); - if (types.size() != 2 || !types.contains(nullschema)) { - final String resultSting = userKey.getID() - + ": Apex currently only supports UNION schemas with 2 options, one must be NULL"; - LOGGER.warn(resultSting); - throw new ContextRuntimeException(resultSting); - } - isnullable = true; - // get the non-null schema given for the union so it can be wrapped - schema = types.get(0); - if (Schema.Type.NULL.equals(schema.getType())) { - schema = types.get(1); - } - if (Schema.Type.NULL.equals(schema.getType())) { - final String resultSting = userKey.getID() - + ": Apex currently only supports UNION schema2 with 2 options, only one can be NULL, and the other cannot be another UNION"; - LOGGER.warn(resultSting); - throw new ContextRuntimeException(resultSting); - } - } - - final Schema.Type avroType = schema.getType(); - - // Check that there is a definition for the mapper for this type - if (!AVRO_OBJECT_MAPPER_MAP.containsKey(avroType) || AVRO_OBJECT_MAPPER_MAP.get(avroType) == null) { - final String resultSting = - userKey.getID() + ": no Avro object mapper defined for Avro type \"" + avroType + "\""; - LOGGER.warn(resultSting); - throw new ContextRuntimeException(resultSting); - } - - // Create a mapper - AvroObjectMapper avroObjectMapper; - try { - avroObjectMapper = AVRO_OBJECT_MAPPER_MAP.get(avroType).newInstance(); - if (isnullable) { - avroObjectMapper = new AvroNullableMapper(avroObjectMapper); - } - - } catch (final Exception e) { - final String resultSting = userKey.getID() + ": could not create an Avro object mapper of type \"" - + AVRO_OBJECT_MAPPER_MAP.get(avroType) + "\" for Avro type \"" + avroType + "\" : " + e; - LOGGER.warn(resultSting, e); - throw new ContextRuntimeException(resultSting, e); - } - - // Set the type and return - avroObjectMapper.init(userKey, avroType); - - return avroObjectMapper; - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java deleted file mode 100644 index 9d24a9a86..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericData.Record; - -/** - * Object mapper for records, uses default behaviour except for a specific default constructor - * implementation. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroRecordObjectMapper extends AvroDirectObjectMapper { - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. - * apache. avro.Schema) - */ - @Override - public Object createNewInstance(final Schema avroSchema) { - return new Record(avroSchema); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java deleted file mode 100644 index 5fba274ce..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java +++ /dev/null @@ -1,261 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import java.io.ByteArrayOutputStream; - -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericDatumReader; -import org.apache.avro.generic.GenericDatumWriter; -import org.apache.avro.generic.GenericRecord; -import org.apache.avro.io.DatumWriter; -import org.apache.avro.io.DecoderFactory; -import org.apache.avro.io.EncoderFactory; -import org.apache.avro.io.JsonDecoder; -import org.apache.avro.io.JsonEncoder; -import org.onap.policy.apex.context.ContextRuntimeException; -import org.onap.policy.apex.context.impl.schema.AbstractSchemaHelper; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; - -/** - * This class is the implementation of the {@link org.onap.policy.apex.context.SchemaHelper} - * interface for Avro schemas. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroSchemaHelper extends AbstractSchemaHelper { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroSchemaHelper.class); - - // The Avro schema for this context schema - private Schema avroSchema; - - // The mapper that translates between Java and Avro objects - private AvroObjectMapper avroObjectMapper; - - @Override - public void init(final AxKey userKey, final AxContextSchema schema) throws ContextRuntimeException { - super.init(userKey, schema); - - // Configure the Avro schema - try { - avroSchema = new Schema.Parser().parse(schema.getSchema()); - } catch (final Exception e) { - final String resultSting = userKey.getID() + ": avro context schema \"" + schema.getID() - + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema(); - LOGGER.warn(resultSting); - throw new ContextRuntimeException(resultSting); - } - - // Get the object mapper for the schema type to a Java class - avroObjectMapper = new AvroObjectMapperFactory().get(userKey, avroSchema); - - // Get the Java type for this schema, if it is a primitive type then we can do direct - // conversion to JAva - setSchemaClass(avroObjectMapper.getJavaClass()); - } - - /** - * Getter to get the Avro schema. - * - * @return the Avro schema - */ - public Schema getAvroSchema() { - return avroSchema; - } - - @Override - public Object getSchemaObject() { - return avroSchema; - } - - @Override - public Object createNewInstance() { - // Create a new instance using the Avro object mapper - final Object newInstance = avroObjectMapper.createNewInstance(avroSchema); - - // If no new instance is created, use default schema handler behavior - if (newInstance != null) { - return newInstance; - } else { - return super.createNewInstance(); - } - } - - @Override - public Object createNewInstance(final String stringValue) { - return unmarshal(stringValue); - } - - @Override - public Object createNewInstance(final Object incomingObject) { - if (incomingObject instanceof JsonElement) { - final Gson gson = new GsonBuilder().serializeNulls().create(); - final String elementJsonString = gson.toJson((JsonElement) incomingObject); - - return createNewInstance(elementJsonString); - } - else { - final String returnString = getUserKey().getID() + ": the object \"" + incomingObject - + "\" is not an instance of JsonObject"; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - } - - @Override - public Object unmarshal(final Object object) { - // If an object is already in the correct format, just carry on - if (passThroughObject(object)) { - return object; - } - - String objectString = getStringObject(object); - - // Translate illegal characters in incoming JSON keys to legal Avro values - objectString = AvroSchemaKeyTranslationUtilities.translateIllegalKeys(objectString, false); - - // Decode the object - Object decodedObject; - try { - final JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(avroSchema, objectString); - decodedObject = new GenericDatumReader(avroSchema).read(null, jsonDecoder); - } catch (final Exception e) { - final String returnString = getUserKey().getID() + ": object \"" + objectString - + "\" Avro unmarshalling failed: " + e.getMessage(); - LOGGER.warn(returnString, e); - throw new ContextRuntimeException(returnString, e); - } - - // Now map the decoded object into something we can handle - return avroObjectMapper.mapFromAvro(decodedObject); - } - - /** - * Check that the incoming object is a string, the incoming object must be a string containing - * Json - * - * @param object incoming object - * @return object as String - */ - private String getStringObject(final Object object) { - try { - if (isObjectString(object)) { - String objectString = object.toString().trim(); - if (objectString.length() == 0) { - return "\"\""; - } else if (objectString.length() == 1) { - return "\"" + objectString + "\""; - } else { - // All strings must be quoted for decoding - if (objectString.charAt(0) != '"') { - objectString = '"' + objectString; - } - if (objectString.charAt(objectString.length() - 1) != '"') { - objectString += '"'; - } - } - return objectString; - } else { - return (String) object; - } - } catch (final ClassCastException e) { - final String returnString = getUserKey().getID() + ": object \"" + object + "\" of type \"" - + (object != null ? object.getClass().getCanonicalName() : "null") + "\" must be assignable to \"" - + getSchemaClass().getCanonicalName() - + "\" or be a Json string representation of it for Avro unmarshalling"; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - } - - private boolean isObjectString(final Object object) { - return object != null && avroSchema.getType().equals(Schema.Type.STRING); - } - - @Override - public String marshal2String(final Object object) { - // Condition the object for Avro encoding - final Object conditionedObject = avroObjectMapper.mapToAvro(object); - - final String jsonString = getJsonString(object, conditionedObject); - - return AvroSchemaKeyTranslationUtilities.translateIllegalKeys(jsonString, true); - } - - private String getJsonString(final Object object, final Object conditionedObject) { - - try (final ByteArrayOutputStream output = new ByteArrayOutputStream();) { - final DatumWriter writer = new GenericDatumWriter<>(avroSchema); - final JsonEncoder jsonEncoder = EncoderFactory.get().jsonEncoder(avroSchema, output, true); - writer.write(conditionedObject, jsonEncoder); - jsonEncoder.flush(); - return new String(output.toByteArray()); - } catch (final Exception e) { - final String returnString = - getUserKey().getID() + ": object \"" + object + "\" Avro marshalling failed: " + e.getMessage(); - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString, e); - } - } - - @Override - public JsonElement marshal2Object(final Object schemaObject) { - // Get the object as a Json string - final String schemaObjectAsString = marshal2String(schemaObject); - - // Get a Gson instance to convert the Json string to an object created by Json - final Gson gson = new Gson(); - - // Convert the Json string into an object - final Object schemaObjectAsObject = gson.fromJson(schemaObjectAsString, Object.class); - - return gson.toJsonTree(schemaObjectAsObject); - } - - /** - * Check if we can pass this object straight through encoding or decoding, is it an object - * native to the schema. - * - * @param object the object to check - * @return true if it's a straight pass through - */ - private boolean passThroughObject(final Object object) { - if (object == null || getSchemaClass() == null) { - return false; - } - - // All strings must be mapped - if (object instanceof String) { - return false; - } - - // Now, check if the object is native - return getSchemaClass().isAssignableFrom(object.getClass()); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java deleted file mode 100644 index 5a8fac404..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import org.onap.policy.apex.context.parameters.SchemaHelperParameters; - -/** - * Schema helper parameter class for the Avro schema helper. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroSchemaHelperParameters extends SchemaHelperParameters { - /** - * The Default Constructor sets the {@link AvroSchemaHelper} as the schema helper class for Avro - * schemas. - */ - public AvroSchemaHelperParameters() { - this.setSchemaHelperPluginClass(AvroSchemaHelper.class.getCanonicalName()); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java deleted file mode 100644 index dc3770a43..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import java.util.Map.Entry; - -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -/** - * This static final class contains utility methods for Avro schemas. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public final class AvroSchemaKeyTranslationUtilities { - // Constants for key replacements - private static final String DOT_STRING = "\\."; - private static final String DOT_STRING_REPLACEMENT = "_DoT_"; - private static final String DASH_STRING = "-"; - private static final String DASH_STRING_REPLACEMENT = "_DasH_"; - - /** - * Default constructor to avoid subclassing. - */ - private AvroSchemaKeyTranslationUtilities() {} - - /** - * Translate characters in JSON keys to values that are legal in Avro. Avro names must start - * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] - * - * @param jsonString The JSON string to translate - * @param revert True if we want to revert the field names to their original values - * @return the translated JSON string - */ - public static String translateIllegalKeys(final String jsonString, final boolean revert) { - if (jsonString == null) { - return jsonString; - } - - // Create a JSON element for the incoming JSON string - final JsonElement jsonElement = - new GsonBuilder().serializeNulls().create().fromJson(jsonString, JsonElement.class); - - final JsonElement translatedJsonElement = translateIllegalKeys(jsonElement, revert); - - return new GsonBuilder().serializeNulls().create().toJson(translatedJsonElement); - } - - /** - * Translate characters in JSON keys to values that are legal in Avro. Avro names must start - * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] - * - * @param jsonElement The JSON element to translate - * @param revert True if we want to revert the field names to their original values - * @return the translated JSON element - */ - public static JsonElement translateIllegalKeys(final JsonElement jsonElement, final boolean revert) { - // We only act on JSON objects and arrays - if (jsonElement.isJsonObject()) { - return translateIllegalKeys(jsonElement.getAsJsonObject(), revert); - } else if (jsonElement.isJsonArray()) { - return translateIllegalKeys(jsonElement.getAsJsonArray(), revert); - } else { - return jsonElement; - } - } - - /** - * Translate characters in JSON keys to values that are legal in Avro. Avro names must start - * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] - * - * @param jsonObject The JSON object to translate - * @param revert True if we want to revert the field names to their original values - * @return the translated JSON element - */ - public static JsonElement translateIllegalKeys(final JsonObject jsonObject, final boolean revert) { - final JsonObject newJsonObject = new JsonObject(); - - for (final Entry jsonObjectEntry : jsonObject.entrySet()) { - newJsonObject.add(translateIllegalKey(jsonObjectEntry.getKey(), revert), - translateIllegalKeys(jsonObjectEntry.getValue(), revert)); - } - - return newJsonObject; - } - - /** - * Translate characters in JSON keys to values that are legal in Avro. Avro names must start - * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] - * - * @param jsonArray The JSON array to translate - * @param revert True if we want to revert the field names to their original values - * @return the translated JSON element - */ - public static JsonElement translateIllegalKeys(final JsonArray jsonArray, final boolean revert) { - final JsonArray newJsonArray = new JsonArray(); - - for (int i = 0; i < jsonArray.size(); i++) { - newJsonArray.add(translateIllegalKeys(jsonArray.get(i), revert)); - } - - return newJsonArray; - } - - /** - * Translate characters in a single JSON key to values that are legal in Avro. Avro names must - * start with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] - * - * @param key The key to translate - * @param revert True if we want to revert the field names to their original values - * @return the translated key - */ - private static String translateIllegalKey(final String key, final boolean revert) { - if (revert) { - return key.replaceAll(DOT_STRING_REPLACEMENT, DOT_STRING).replaceAll(DASH_STRING_REPLACEMENT, DASH_STRING); - } else { - return key.replaceAll(DOT_STRING, DOT_STRING_REPLACEMENT).replaceAll(DASH_STRING, DASH_STRING_REPLACEMENT); - } - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java deleted file mode 100644 index cb3625f31..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import org.apache.avro.Schema; -import org.apache.avro.Schema.Type; -import org.apache.avro.util.Utf8; -import org.onap.policy.apex.context.ContextRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class does string mapping from the Avro Utf8 class to the Java String class. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AvroStringObjectMapper implements AvroObjectMapper { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroStringObjectMapper.class); - - // The user keyAvro type for direct mapping - private AxKey userKey; - private Type avroType; - - // The Apex compatible class - private final Class schemaClass = String.class; - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getJavaClass() - */ - @Override - public Class getJavaClass() { - return schemaClass; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#setAvroType(org.apache. - * avro. Schema.Type) - */ - @Override - public void init(final AxKey initUserKey, final Type initAvroType) { - this.userKey = initUserKey; - this.avroType = initAvroType; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. - * apache. avro.Schema) - */ - @Override - public Object createNewInstance(final Schema avroSchema) { - // By default, we do not create an instance, normal Java object creation for strings is - // sufficient - return null; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getAvroType() - */ - @Override - public Type getAvroType() { - return avroType; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapFromAvro(java.lang. - * Object) - */ - @Override - public Object mapFromAvro(final Object avroObject) { - // The Avro object should be a Utf8 object - if (!(avroObject instanceof Utf8)) { - final String returnString = - userKey.getID() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass() - + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - - return avroObject.toString(); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapToAvro(java.lang.Object) - */ - @Override - public Object mapToAvro(final Object object) { - if (object == null) { - final String returnString = userKey.getID() + ": cannot encode a null object of class \"" - + schemaClass.getCanonicalName() + "\""; - LOGGER.warn(returnString); - throw new ContextRuntimeException(returnString); - } - - return object; - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java deleted file mode 100644 index 93f4943d5..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Implements Avro schem handling for use in event fields and - * context albums in APEX. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.plugins.context.schema.avro; diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java deleted file mode 100644 index 65eef39c2..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.apache.avro.generic.GenericData.Array; -import org.apache.avro.generic.GenericRecord; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaAAI { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String aaiInventoryResponseSchema; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - aaiInventoryResponseSchema = - TextFileUtils.getTextFileAsString("src/test/resources/avsc/AAIInventoryResponseItemType.avsc"); - } - - @Test - public void testAAIResponsePolicy() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", aaiInventoryResponseSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final Array newArrayEmpty = (Array) schemaHelper.createNewInstance(); - assertEquals(0, newArrayEmpty.size()); - - final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/AAIResponse4Policy.json"); - final Array newArrayFull = (Array) schemaHelper.createNewInstance(inString); - final String vnfName = ((GenericRecord) ((GenericRecord) newArrayFull.get(0)).get("generic_DasH_vnf")) - .get("vnf_DasH_name").toString(); - assertEquals("ZRDM2MMEX39", vnfName); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java deleted file mode 100644 index 21fab66d9..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.apache.avro.generic.GenericData.Array; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaArray { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String longArraySchema; - private String addressArraySchema; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - longArraySchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/ArrayExampleLong.avsc"); - addressArraySchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/ArrayExampleAddress.avsc"); - } - - @Test - public void testArrayInit() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", addressArraySchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final Array newArrayEmpty = (Array) schemaHelper.createNewInstance(); - assertEquals(0, newArrayEmpty.size()); - - final String inString = - TextFileUtils.getTextFileAsString("src/test/resources/data/ArrayExampleAddressFull.json"); - final Array newArrayFull = (Array) schemaHelper.createNewInstance(inString); - assertEquals("{\"streetaddress\": \"1600 Pennsylvania Avenue\", \"city\": \"Washington DC\"}", - newArrayFull.get(0).toString()); - } - - @Test - public void testLongArrayUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", longArraySchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleLongNull.json"); - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleLongFull.json"); - } - - @Test - public void testAddressArrayUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", addressArraySchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleAddressNull.json"); - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleAddressFull.json"); - } - - private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { - final String inString = TextFileUtils.getTextFileAsString(fileName); - final Array schemaObject = (Array) schemaHelper.unmarshal(inString); - final String outString = schemaHelper.marshal2String(schemaObject); - assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java deleted file mode 100644 index ae19cd31a..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.IOException; - -import org.apache.avro.generic.GenericData.EnumSymbol; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaEnum { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String enumSchema; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - enumSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/EnumSchema.avsc"); - } - - @Test - public void testEnumInit() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", enumSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final EnumSymbol newEnumEmpty = (EnumSymbol) schemaHelper.createNewInstance(); - assertEquals("SPADES", newEnumEmpty.toString()); - - final EnumSymbol newEnumFull = (EnumSymbol) schemaHelper.createNewInstance("\"HEARTS\""); - assertEquals("HEARTS", newEnumFull.toString()); - } - - @Test - public void testEnumUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", enumSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleHearts.json"); - - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", - e.getMessage()); - } - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", - e.getMessage()); - } - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad0.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed: Unknown symbol in enum TWEED", - e.getMessage()); - } - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad1.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed: Unknown symbol in enum Hearts", - e.getMessage()); - } - } - - private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { - final String inString = TextFileUtils.getTextFileAsString(fileName); - final EnumSymbol decodedObject = (EnumSymbol) schemaHelper.unmarshal(inString); - final String outString = schemaHelper.marshal2String(decodedObject); - assertEquals(inString.replaceAll("[\\r?\\n]+", " "), outString.replaceAll("[\\r?\\n]+", " ")); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java deleted file mode 100644 index 41f622115..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; - -import org.apache.avro.generic.GenericData.Fixed; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaFixed { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String fixedSchema; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - fixedSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/FixedSchema.avsc"); - } - - @Test - public void testFixedInit() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", fixedSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - try { - schemaHelper.createNewInstance(); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"org.apache.avro.generic.GenericData.Fixed\" using the default constructor \"Fixed()\"", - e.getMessage()); - } - - final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/FixedExampleGood.json"); - final Fixed newFixedFull = (Fixed) schemaHelper.createNewInstance(inString); - assertTrue(newFixedFull.toString().startsWith("[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65")); - assertTrue(newFixedFull.toString().endsWith("53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70]")); - } - - @Test - public void testFixedUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", fixedSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleGood.json"); - - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", - e.getMessage()); - } - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", - e.getMessage()); - } - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: object \"\"BADBAD\"\" Avro unmarshalling failed: Expected fixed length 64, but got6", - e.getMessage()); - } - try { - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json"); - fail("This test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: object \"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" Avro unmarshalling failed: Expected fixed length 64, but got65", - e.getMessage()); - } - } - - private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { - final String inString = TextFileUtils.getTextFileAsString(fileName); - final Fixed decodedObject = (Fixed) schemaHelper.unmarshal(inString); - final String outString = schemaHelper.marshal2String(decodedObject); - assertEquals(inString.replaceAll("[\\r?\\n]+", " "), outString.replaceAll("[\\r?\\n]+", " ")); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java deleted file mode 100644 index 1e1a0bee0..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java +++ /dev/null @@ -1,123 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaHelperBadSchemas { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - - @Before - public void initTest() { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - } - - @Test - public void badSchemaTest() { - final AxContextSchema avroBadSchema0 = new AxContextSchema(new AxArtifactKey("AvroBad0", "0.0.1"), "Avro", "}"); - schemas.getSchemasMap().put(avroBadSchema0.getKey(), avroBadSchema0); - - try { - new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema0.getKey()); - fail("This test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad0:0.0.1\" schema is invalid")); - } - - final AxContextSchema avroBadSchema1 = new AxContextSchema(new AxArtifactKey("AvroBad1", "0.0.1"), "Avro", ""); - schemas.getSchemasMap().put(avroBadSchema1.getKey(), avroBadSchema1); - - try { - new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema1.getKey()); - fail("This test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad1:0.0.1\" schema is invalid")); - } - - final AxContextSchema avroBadSchema2 = - new AxContextSchema(new AxArtifactKey("AvroBad2", "0.0.1"), "Avro", "{}"); - schemas.getSchemasMap().put(avroBadSchema2.getKey(), avroBadSchema2); - - try { - new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema2.getKey()); - fail("This test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad2:0.0.1\" schema is invalid")); - } - - final AxContextSchema avroBadSchema3 = - new AxContextSchema(new AxArtifactKey("AvroBad3", "0.0.1"), "Avro", "{zooby}"); - schemas.getSchemasMap().put(avroBadSchema3.getKey(), avroBadSchema3); - - try { - new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema3.getKey()); - fail("This test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad3:0.0.1\" schema is invalid")); - } - - final AxContextSchema avroBadSchema4 = - new AxContextSchema(new AxArtifactKey("AvroBad4", "0.0.1"), "Avro", "{\"zooby\"}"); - schemas.getSchemasMap().put(avroBadSchema4.getKey(), avroBadSchema4); - - try { - new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema4.getKey()); - fail("This test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad4:0.0.1\" schema is invalid")); - } - - final AxContextSchema avroBadSchema5 = - new AxContextSchema(new AxArtifactKey("AvroBad5", "0.0.1"), "Avro", "{\"type\": \"zooby\"}"); - schemas.getSchemasMap().put(avroBadSchema5.getKey(), avroBadSchema5); - - try { - new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema5.getKey()); - fail("This test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad5:0.0.1\" schema is invalid")); - } - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java deleted file mode 100644 index a710a2376..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java +++ /dev/null @@ -1,277 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaHelperMarshal { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - - @Before - public void initTest() { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - } - - @Test - public void testNullMarshal() { - final AxContextSchema avroNullSchema = - new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "Avro", "{\"type\": \"null\"}"); - - schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema); - final SchemaHelper schemaHelper0 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey()); - - assertEquals("null", schemaHelper0.marshal2String(null)); - assertEquals("null", schemaHelper0.marshal2String(123)); - assertEquals("null", schemaHelper0.marshal2String("Everything is marshalled to Null, no matter what it is")); - } - - @Test - public void testBooleanMarshal() { - final AxContextSchema avroBooleanSchema = - new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "Avro", "{\"type\": \"boolean\"}"); - - schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema); - final SchemaHelper schemaHelper1 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey()); - - assertEquals("true", schemaHelper1.marshal2String(true)); - assertEquals("false", schemaHelper1.marshal2String(false)); - try { - schemaHelper1.marshal2String(0); - fail("Test should throw an exception here"); - } catch (final Exception e) { - e.printStackTrace(); - assertEquals( - "AvroTest:0.0.1: object \"0\" Avro marshalling failed: java.lang.Integer cannot be cast to java.lang.Boolean", - e.getMessage()); - } - try { - schemaHelper1.marshal2String("0"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - e.printStackTrace(); - assertEquals( - "AvroTest:0.0.1: object \"0\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Boolean", - e.getMessage()); - } - } - - @Test - public void testIntMarshal() { - final AxContextSchema avroIntSchema = - new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "Avro", "{\"type\": \"int\"}"); - - schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema); - final SchemaHelper schemaHelper2 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey()); - - assertEquals("0", schemaHelper2.marshal2String(0)); - assertEquals("1", schemaHelper2.marshal2String(1)); - assertEquals("-1", schemaHelper2.marshal2String(-1)); - assertEquals("1", schemaHelper2.marshal2String(1.23)); - assertEquals("-1", schemaHelper2.marshal2String(-1.23)); - assertEquals("2147483647", schemaHelper2.marshal2String(2147483647)); - assertEquals("-2147483648", schemaHelper2.marshal2String(-2147483648)); - try { - schemaHelper2.marshal2String("Hello"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Number")); - } - try { - schemaHelper2.marshal2String(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\"")); - } - } - - @Test - public void testLongMarshal() { - final AxContextSchema avroLongSchema = - new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "Avro", "{\"type\": \"long\"}"); - - schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema); - final SchemaHelper schemaHelper3 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey()); - - assertEquals("0", schemaHelper3.marshal2String(0L)); - assertEquals("1", schemaHelper3.marshal2String(1L)); - assertEquals("-1", schemaHelper3.marshal2String(-1L)); - assertEquals("9223372036854775807", schemaHelper3.marshal2String(9223372036854775807L)); - assertEquals("-9223372036854775808", schemaHelper3.marshal2String(-9223372036854775808L)); - try { - schemaHelper3.marshal2String("Hello"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Long")); - } - try { - schemaHelper3.marshal2String(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\"")); - } - } - - @Test - public void testFloatMarshal() { - final AxContextSchema avroFloatSchema = - new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "Avro", "{\"type\": \"float\"}"); - - schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema); - final SchemaHelper schemaHelper4 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey()); - - assertEquals("0.0", schemaHelper4.marshal2String(0F)); - assertEquals("1.0", schemaHelper4.marshal2String(1F)); - assertEquals("-1.0", schemaHelper4.marshal2String(-1F)); - assertEquals("1.23", schemaHelper4.marshal2String(1.23F)); - assertEquals("-1.23", schemaHelper4.marshal2String(-1.23F)); - assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F)); - assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F)); - assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F)); - assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F)); - try { - schemaHelper4.marshal2String("Hello"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Float")); - } - try { - schemaHelper4.marshal2String(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\"")); - } - } - - - @Test - public void testDoubleMarshal() { - final AxContextSchema avroDoubleSchema = - new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "Avro", "{\"type\": \"double\"}"); - - schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema); - final SchemaHelper schemaHelper5 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey()); - - assertEquals("0.0", schemaHelper5.marshal2String(0D)); - assertEquals("1.0", schemaHelper5.marshal2String(1D)); - assertEquals("-1.0", schemaHelper5.marshal2String(-1D)); - assertEquals("1.23", schemaHelper5.marshal2String(1.23)); - assertEquals("-1.23", schemaHelper5.marshal2String(-1.23)); - assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18)); - assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18)); - assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18)); - assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18)); - try { - schemaHelper5.marshal2String("Hello"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Double")); - } - try { - schemaHelper5.marshal2String(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\"")); - } - } - - @Test - public void testStringMarshal() { - final AxContextSchema avroStringSchema = - new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"string\"}"); - - schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema); - final SchemaHelper schemaHelper7 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey()); - - assertEquals("\"0\"", schemaHelper7.marshal2String("0")); - assertEquals("\"1\"", schemaHelper7.marshal2String("1")); - assertEquals("\"-1\"", schemaHelper7.marshal2String("-1")); - assertEquals("\"1.23\"", schemaHelper7.marshal2String("1.23")); - assertEquals("\"-1.23\"", schemaHelper7.marshal2String("-1.23")); - assertEquals("\"9223372036854775807\"", schemaHelper7.marshal2String("9223372036854775807")); - assertEquals("\"-9223372036854775808\"", schemaHelper7.marshal2String("-9223372036854775808")); - assertEquals("\"9223372036854775808\"", schemaHelper7.marshal2String("9223372036854775808")); - assertEquals("\"-9223372036854775809\"", schemaHelper7.marshal2String("-9223372036854775809")); - assertEquals("\"Hello\"", schemaHelper7.marshal2String("Hello")); - try { - schemaHelper7.marshal2String(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\"")); - } - } - - @Test - public void testBytesMarshal() { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"bytes\"}"); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final byte[] helloBytes = {104, 101, 108, 108, 111}; - final String helloOut = schemaHelper.marshal2String(helloBytes); - assertEquals("\"hello\"", helloOut); - - try { - schemaHelper.marshal2String(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Byte[]\"")); - } - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java deleted file mode 100644 index 725ebb221..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java +++ /dev/null @@ -1,371 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.apache.avro.util.Utf8; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaHelperUnmarshal { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - - @Before - public void initTest() { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - } - - // @Test - public void testNullUnmarshal() { - final AxContextSchema avroNullSchema = - new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "Avro", "{\"type\": \"null\"}"); - - schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema); - final SchemaHelper schemaHelper0 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey()); - - try { - schemaHelper0.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("AvroTest:0.0.1: could not create an instance, schema class for the schema is null", - e.getMessage()); - } - - assertEquals(null, schemaHelper0.unmarshal("null")); - - try { - schemaHelper0.unmarshal("123"); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: Expected null. Got VALUE_NUMBER_INT", - e.getMessage()); - } - } - - // @Test - public void testBooleanUnmarshal() { - final AxContextSchema avroBooleanSchema = - new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "Avro", "{\"type\": \"boolean\"}"); - - schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema); - final SchemaHelper schemaHelper1 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey()); - - try { - schemaHelper1.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" using the default constructor \"Boolean()\"", - e.getMessage()); - } - assertEquals(true, schemaHelper1.createNewInstance("true")); - - assertEquals(true, schemaHelper1.unmarshal("true")); - assertEquals(false, schemaHelper1.unmarshal("false")); - try { - schemaHelper1.unmarshal(0); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: object \"0\" Avro unmarshalling failed: Expected boolean. Got VALUE_NUMBER_INT", - e.getMessage()); - } - } - - // @Test - public void testIntUnmarshal() { - final AxContextSchema avroIntSchema = - new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "Avro", "{\"type\": \"int\"}"); - - schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema); - final SchemaHelper schemaHelper2 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey()); - - try { - schemaHelper2.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" using the default constructor \"Integer()\"", - e.getMessage()); - } - assertEquals(123, schemaHelper2.createNewInstance("123")); - - assertEquals(0, schemaHelper2.unmarshal("0")); - assertEquals(1, schemaHelper2.unmarshal("1")); - assertEquals(-1, schemaHelper2.unmarshal("-1")); - assertEquals(1, schemaHelper2.unmarshal("1.23")); - assertEquals(-1, schemaHelper2.unmarshal("-1.23")); - assertEquals(2147483647, schemaHelper2.unmarshal("2147483647")); - assertEquals(-2147483648, schemaHelper2.unmarshal("-2147483648")); - try { - schemaHelper2.unmarshal("2147483648"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: Numeric value (2147483648) out of range of int")); - } - try { - schemaHelper2.unmarshal("-2147483649"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: Numeric value (-2147483649) out of range of int")); - } - try { - schemaHelper2.unmarshal(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); - } - } - - // @Test - public void testLongUnmarshal() { - final AxContextSchema avroLongSchema = - new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "Avro", "{\"type\": \"long\"}"); - - schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema); - final SchemaHelper schemaHelper3 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey()); - - try { - schemaHelper3.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" using the default constructor \"Long()\"", - e.getMessage()); - } - assertEquals(123456789L, schemaHelper3.createNewInstance("123456789")); - - assertEquals(0L, schemaHelper3.unmarshal("0")); - assertEquals(1L, schemaHelper3.unmarshal("1")); - assertEquals(-1L, schemaHelper3.unmarshal("-1")); - assertEquals(1L, schemaHelper3.unmarshal("1.23")); - assertEquals(-1L, schemaHelper3.unmarshal("-1.23")); - assertEquals(9223372036854775807L, schemaHelper3.unmarshal("9223372036854775807")); - assertEquals(-9223372036854775808L, schemaHelper3.unmarshal("-9223372036854775808")); - try { - schemaHelper3.unmarshal("9223372036854775808"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: Numeric value (9223372036854775808) out of range of long")); - } - try { - schemaHelper3.unmarshal("-9223372036854775809"); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith( - "AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: Numeric value (-9223372036854775809) out of range of long")); - } - try { - schemaHelper3.unmarshal("\"Hello\""); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected long. Got VALUE_STRING")); - } - try { - schemaHelper3.unmarshal(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); - } - } - - // @Test - public void testFloatUnmarshal() { - final AxContextSchema avroFloatSchema = - new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "Avro", "{\"type\": \"float\"}"); - - schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema); - final SchemaHelper schemaHelper4 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey()); - - try { - schemaHelper4.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" using the default constructor \"Float()\"", - e.getMessage()); - } - assertEquals(1.2345F, schemaHelper4.createNewInstance("1.2345")); - - assertEquals(0.0F, schemaHelper4.unmarshal("0")); - assertEquals(1.0F, schemaHelper4.unmarshal("1")); - assertEquals(-1.0F, schemaHelper4.unmarshal("-1")); - assertEquals(1.23F, schemaHelper4.unmarshal("1.23")); - assertEquals(-1.23F, schemaHelper4.unmarshal("-1.23")); - assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775807")); - assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775808")); - assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775808")); - assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775809")); - try { - schemaHelper4.unmarshal("\"Hello\""); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected float. Got VALUE_STRING")); - } - try { - schemaHelper4.unmarshal(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); - } - } - - // @Test - public void testDoubleUnmarshal() { - final AxContextSchema avroDoubleSchema = - new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "Avro", "{\"type\": \"double\"}"); - - schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema); - final SchemaHelper schemaHelper5 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey()); - - try { - schemaHelper5.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" using the default constructor \"Double()\"", - e.getMessage()); - } - assertEquals(1.2345E06, schemaHelper5.createNewInstance("1.2345E06")); - - assertEquals(0.0, schemaHelper5.unmarshal("0")); - assertEquals(1.0, schemaHelper5.unmarshal("1")); - assertEquals(-1.0, schemaHelper5.unmarshal("-1")); - assertEquals(1.23, schemaHelper5.unmarshal("1.23")); - assertEquals(-1.23, schemaHelper5.unmarshal("-1.23")); - assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775807")); - assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775808")); - assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775808")); - assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775809")); - try { - schemaHelper5.unmarshal("\"Hello\""); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected double. Got VALUE_STRING")); - } - try { - schemaHelper5.unmarshal(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); - } - } - - @Test - public void testStringUnmarshal() { - final AxContextSchema avroStringSchema = - new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"string\"}"); - - schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema); - final SchemaHelper schemaHelper7 = - new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey()); - - assertEquals("", schemaHelper7.createNewInstance("")); - assertEquals("1.2345E06", schemaHelper7.createNewInstance("1.2345E06")); - - assertEquals("0", schemaHelper7.unmarshal("0")); - assertEquals("1", schemaHelper7.unmarshal("1")); - assertEquals("-1", schemaHelper7.unmarshal("-1")); - assertEquals("1.23", schemaHelper7.unmarshal("1.23")); - assertEquals("-1.23", schemaHelper7.unmarshal("-1.23")); - assertEquals("9223372036854775807", schemaHelper7.unmarshal("9223372036854775807")); - assertEquals("-9223372036854775808", schemaHelper7.unmarshal("-9223372036854775808")); - assertEquals("9223372036854775808", schemaHelper7.unmarshal("9223372036854775808")); - assertEquals("-9223372036854775809", schemaHelper7.unmarshal("-9223372036854775809")); - assertEquals("Hello", schemaHelper7.unmarshal("Hello")); - assertEquals("Hello", schemaHelper7.unmarshal(new Utf8("Hello"))); - try { - schemaHelper7.unmarshal(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); - } - } - - @Test - public void testBytesUnmarshal() { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"bytes\"}"); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - try { - schemaHelper.createNewInstance(); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals( - "AvroTest:0.0.1: could not create an instance of class \"java.lang.Byte[]\" using the default constructor \"Byte[]()\"", - e.getMessage()); - } - final byte[] newBytes = (byte[]) schemaHelper.createNewInstance("\"hello\""); - assertEquals(5, newBytes.length); - assertEquals(104, newBytes[0]); - assertEquals(101, newBytes[1]); - assertEquals(108, newBytes[2]); - assertEquals(108, newBytes[3]); - assertEquals(111, newBytes[4]); - - try { - schemaHelper.unmarshal(null); - fail("Test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().equals( - "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); - } - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java deleted file mode 100644 index 33ca512b9..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - -import org.apache.avro.util.Utf8; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaMap { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String longMapSchema; - private String addressMapSchema; - private String addressMapSchemaInvalidFields; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - longMapSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleLong.avsc"); - addressMapSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddress.avsc"); - addressMapSchemaInvalidFields = - TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddressInvalidFields.avsc"); - } - - @Test - public void testMapInit() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", addressMapSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final HashMap newMapEmpty = (HashMap) schemaHelper.createNewInstance(); - assertEquals(0, newMapEmpty.size()); - - final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/MapExampleAddressFull.json"); - final HashMap newMapFull = (HashMap) schemaHelper.createNewInstance(inString); - - assertEquals("{\"streetaddress\": \"221 B Baker St.\", \"city\": \"London\"}", - newMapFull.get(new Utf8("address2")).toString()); - } - - @Test - public void testLongMapUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "Avro", longMapSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleLongNull.json"); - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleLongFull.json"); - } - - @Test - public void testAddressMapUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "Avro", addressMapSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressNull.json"); - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressFull.json"); - } - - @Test - public void testAddressMapUnmarshalMarshalInvalidFields() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "Avro", addressMapSchemaInvalidFields); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressInvalidFields.json"); - } - - private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { - final String originalInString = TextFileUtils.getTextFileAsString(fileName); - final HashMap firstDecodedMap = (HashMap) schemaHelper.unmarshal(originalInString); - - final String outString = schemaHelper.marshal2String(firstDecodedMap); - - final File tempOutFile = File.createTempFile("ApexAvro", ".json"); - TextFileUtils.putStringAsFile(outString, tempOutFile); - - final String decodeEncodeInString = TextFileUtils.getTextFileAsString(fileName); - tempOutFile.delete(); - - final HashMap secondDecodedMap = (HashMap) schemaHelper.unmarshal(decodeEncodeInString); - - // Now check that our doubly encoded map equals the first decoded map, Java map equals - // checks values and keys - assertEquals(firstDecodedMap, secondDecodedMap); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java deleted file mode 100644 index e14236064..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.apache.avro.generic.GenericRecord; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaRecord { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String recordSchema; - private String recordSchemaVPN; - private String recordSchemaVPNReuse; - private String recordSchemaInvalidFields; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - recordSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExample.avsc"); - recordSchemaVPN = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPN.avsc"); - recordSchemaVPNReuse = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPNReuse.avsc"); - recordSchemaInvalidFields = - TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleInvalidFields.avsc"); - } - - @Test - public void testRecordInit() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final GenericRecord newRecordEmpty = (GenericRecord) schemaHelper.createNewInstance(); - assertEquals(null, newRecordEmpty.get("passwordHash")); - - final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/RecordExampleFull.json"); - final GenericRecord newRecordFull = (GenericRecord) schemaHelper.createNewInstance(inString); - assertEquals("gobbledygook", newRecordFull.get("passwordHash").toString()); - } - - @Test - public void testRecordUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleNull.json"); - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleFull.json"); - } - - @Test - public void testRecordUnmarshalMarshalInvalid() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchemaInvalidFields); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleInvalidFields.json"); - } - - @Test - public void testVPNRecordUnmarshalMarshal() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchemaVPN); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleVPNFull.json"); - } - - @Test - public void testVPNRecordReuse() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchemaVPNReuse); - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - } - - private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { - final String inString = TextFileUtils.getTextFileAsString(fileName); - final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString); - final String outString = schemaHelper.marshal2String(decodedObject); - assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java deleted file mode 100644 index 100b51d44..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.apache.avro.generic.GenericRecord; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - * @version - */ -public class TestAvroSchemaUnion { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String uinionSchema; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - uinionSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/UnionExample.avsc"); - } - - @Ignore - @Test - public void testUnionAllFields() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", uinionSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleAllFields.json"); - final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString); - - assertEquals("Ben", user.get("name").toString()); - assertEquals(7, user.get("favourite_number")); - assertEquals("red", user.get("favourite_colour").toString()); - } - - @Ignore - @Test - public void testUnionOptionalField() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", uinionSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final String inString = - TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleOptionalField.json"); - final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString); - - assertEquals("Ben", user.get("name").toString()); - assertEquals(7, user.get("favourite_number")); - assertEquals("red", user.get("favourite_colour").toString()); - } - - @Ignore - @Test - public void testUnionNullField() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", uinionSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleNullField.json"); - final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString); - - assertEquals("Ben", user.get("name").toString()); - assertEquals(7, user.get("favourite_number")); - assertEquals("red", user.get("favourite_colour").toString()); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java b/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java deleted file mode 100644 index 026125af9..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.schema.avro; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.apache.avro.Schema; -import org.apache.avro.generic.GenericData; -import org.apache.avro.generic.GenericData.Record; -import org.apache.avro.generic.GenericRecord; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.SchemaHelper; -import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestHealthCheckSchema { - private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); - private AxContextSchemas schemas; - private String healthCheckSchema; - - @Before - public void initTest() throws IOException { - schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); - ModelService.registerModel(AxContextSchemas.class, schemas); - - new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - healthCheckSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/HealthCheckBodyType.avsc"); - } - - - @Test - public void testHealthCheck() throws IOException { - final AxContextSchema avroSchema = - new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", healthCheckSchema); - - schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); - final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - - testUnmarshalMarshal(schemaHelper, "src/test/resources/data/HealthCheckEvent.json"); - - final GenericRecord healthCheckRecord = (Record) schemaHelper.createNewInstance(); - final Schema healthCheckRecordSchema = healthCheckRecord.getSchema(); - - final GenericRecord inputRecord = new GenericData.Record(healthCheckRecordSchema.getField("input").schema()); - final Schema inputRecordRecordSchema = inputRecord.getSchema(); - - final GenericRecord actionIndentifiersRecord = - new GenericData.Record(inputRecordRecordSchema.getField("action_DasH_identifiers").schema()); - - final GenericRecord commonHeaderRecord = - new GenericData.Record(inputRecordRecordSchema.getField("common_DasH_header").schema()); - final Schema commonHeaderRecordSchema = commonHeaderRecord.getSchema(); - - final GenericRecord commonHeaderFlagsRecord = - new GenericData.Record(commonHeaderRecordSchema.getField("flags").schema()); - - healthCheckRecord.put("input", inputRecord); - inputRecord.put("action_DasH_identifiers", actionIndentifiersRecord); - inputRecord.put("common_DasH_header", commonHeaderRecord); - commonHeaderRecord.put("flags", commonHeaderFlagsRecord); - - inputRecord.put("action", "HealthCheck"); - inputRecord.put("payload", - "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\",\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}"); - - actionIndentifiersRecord.put("vnf_DasH_id", "49414df5-3482-4fd8-9952-c463dff2770b"); - - commonHeaderRecord.put("request_DasH_id", "afr-request3"); - commonHeaderRecord.put("originator_DasH_id", "AFR"); - commonHeaderRecord.put("api_DasH_ver", "2.15"); - commonHeaderRecord.put("sub_DasH_request_DasH_id", "AFR-subrequest"); - commonHeaderRecord.put("timestamp", "2017-11-06T15:15:18.97Z"); - - commonHeaderFlagsRecord.put("ttl", "10000"); - commonHeaderFlagsRecord.put("force", "TRUE"); - commonHeaderFlagsRecord.put("mode", "EXCLUSIVE"); - - final String eventString = TextFileUtils.getTextFileAsString("src/test/resources/data/HealthCheckEvent.json"); - final String outString = schemaHelper.marshal2String(healthCheckRecord); - assertEquals(eventString.toString().replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); - } - - private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { - final String inString = TextFileUtils.getTextFileAsString(fileName); - final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString); - final String outString = schemaHelper.marshal2String(decodedObject); - assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc deleted file mode 100644 index d4ae592a1..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc +++ /dev/null @@ -1,70 +0,0 @@ -{ - "type": "array", - "items": { - "type": "record", - "name": "AAIInventoryResponseItem_Type", - "fields": [ - { - "name": "model_DasH_name", - "type": "string" - }, - { - "name": "extra_DasH_properties", - "type": { - "type": "record", - "name": "AAIInventoryResponseItemExtraProperties_Type", - "fields": [] - } - }, - { - "name": "generic_DasH_vnf", - "type": { - "type": "record", - "name": "AAIInventoryResponseItemGenericVNF_Type", - "fields": [ - { - "name": "vnf_DasH_id", - "type": "string" - }, - { - "name": "vnf_DasH_name", - "type": "string" - }, - { - "name": "vnf_DasH_type", - "type": "string" - }, - { - "name": "service_DasH_id", - "type": "string" - }, - { - "name": "orchestration_DasH_status", - "type": "string" - }, - { - "name": "in_DasH_maint", - "type": "boolean" - }, - { - "name": "is_DasH_closed_DasH_loop_DasH_disabled", - "type": "boolean" - }, - { - "name": "resource_DasH_version", - "type": "string" - }, - { - "name": "model_DasH_invariant_DasH_id", - "type": "string" - }, - { - "name": "model_DasH_version_DasH_id", - "type": "string" - } - ] - } - } - ] - } -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc deleted file mode 100644 index 0967d6210..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "type": "array", "items": { - "type" : "record", - "name" : "AddressUSRecord", - "fields" : [ - {"name": "streetaddress", "type": "string"}, - {"name": "city", "type": "string"} - ] - } -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc deleted file mode 100644 index 91f391a89..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "array", "items": "long" -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/EnumSchema.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/EnumSchema.avsc deleted file mode 100644 index ea5c5b7b1..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/EnumSchema.avsc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "type": "enum", - "name": "Suit", - "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"] -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/FixedSchema.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/FixedSchema.avsc deleted file mode 100644 index 4642ef577..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/FixedSchema.avsc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "type" : "fixed", - "name" : "binaryData", - "size" : 64 -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc deleted file mode 100644 index 2db1d696d..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc +++ /dev/null @@ -1,76 +0,0 @@ -{ - "type" : "record", - "name" : "HealthCheckBody_Type", - "namespace" : "com.ericsson.apex.onap.tlgoal2017", - "fields" : [ - { - "name": "input", - "type": { - "type" : "record", - "name" : "InputRecord", - "fields" : [ - { - "name": "action", "type": "string" - }, - { - "name": "action_DasH_identifiers", - "type": { - "type" : "record", - "name" : "ActionIdentifiersRecord", - "fields" : [ - { - "name": "vnf_DasH_id", "type": "string" - } - ] - } - }, - { - "name": "common_DasH_header", - "type": { - "type" : "record", - "name" : "CommonHeaderRecord", - "fields" : [ - { - "name": "request_DasH_id", "type": "string" - }, - { - "name": "originator_DasH_id", "type": "string" - }, - { - "name": "api_DasH_ver", "type": "string" - }, - { - "name": "sub_DasH_request_DasH_id", "type": "string" - }, - { - "name": "timestamp", "type": "string" - }, - { - "name": "flags", - "type": { - "type" : "record", - "name" : "FlagsRecord", - "fields" : [ - { - "name": "ttl", "type": "string" - }, - { - "name": "force", "type": "string" - }, - { - "name": "mode", "type": "string" - } - ] - } - } - ] - } - }, - { - "name": "payload", "type": "string" - } - ] - } - } - ] -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc deleted file mode 100644 index f8457c690..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "type": "map", "values": { - "type" : "record", - "name" : "AddressUSRecord", - "fields" : [ - {"name": "streetaddress", "type": "string"}, - {"name": "city", "type": "string"} - ] - } -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc deleted file mode 100644 index 48c476065..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "type": "map", "values": { - "type" : "record", - "name" : "AddressUSRecord", - "fields" : [ - {"name": "street_DasH_address", "type": "string"}, - {"name": "the_DoT_city", "type": "string"} - ] - } -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc deleted file mode 100644 index 0bb3729ed..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "map", "values": "long" -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExample.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExample.avsc deleted file mode 100644 index 274735532..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExample.avsc +++ /dev/null @@ -1,172 +0,0 @@ -{ - "type": "record", - "name": "User", - "namespace": "com.example.avro", - "doc": "This is a user record in a fictitious to-do-list management app. It supports arbitrary grouping and nesting of items, and allows you to add items by email or by tweeting.\n\nNote this app doesn't actually exist. The schema is just a demo for [Avrodoc](https://github.com/ept/avrodoc)!", - "fields": [ - {"name": "firstname", "type": "string"}, - {"name": "lastname", "type": "string"}, - { - "name": "address", - "type": { - "type" : "record", - "name" : "AddressUSRecord", - "fields" : [ - {"name": "streetaddress", "type": "string"}, - {"name": "city", "type": "string"} - ] - } - }, - { - "name": "id", - "doc": "System-assigned numeric user ID. Cannot be changed by the user.", - "type": "int" - }, - { - "name": "username", - "doc": "The username chosen by the user. Can be changed by the user.", - "type": "string" - }, - { - "name": "passwordHash", - "doc": "The user's password, hashed using [scrypt](http://www.tarsnap.com/scrypt.html).", - "type": "string" - }, - { - "name": "signupDate", - "doc": "Timestamp (milliseconds since epoch) when the user signed up", - "type": "long" - }, - { - "name": "emailAddresses", - "doc": "All email addresses on the user's account", - "type": { - "type": "array", - "items": { - "type": "record", - "name": "EmailAddress", - "doc": "Stores details about an email address that a user has associated with their account.", - "fields": [ - { - "name": "address", - "doc": "The email address, e.g. `foo@example.com`", - "type": "string" - }, - { - "name": "verified", - "doc": "true if the user has clicked the link in a confirmation email to this address.", - "type": "boolean", - "default": false - }, - { - "name": "dateAdded", - "doc": "Timestamp (milliseconds since epoch) when the email address was added to the account.", - "type": "long" - }, - { - "name": "dateBounced", - "doc": "Timestamp (milliseconds since epoch) when an email sent to this address last bounced. Reset to null when the address no longer bounces.", - "type": ["null", "long"] - } - ] - } - } - }, - { - "name": "twitterAccounts", - "doc": "All Twitter accounts that the user has OAuthed", - "type": { - "type": "array", - "items": { - "type": "record", - "name": "TwitterAccount", - "doc": "Stores access credentials for one Twitter account, as granted to us by the user by OAuth.", - "fields": [ - { - "name": "status", - "doc": "Indicator of whether this authorization is currently active, or has been revoked", - "type": { - "type": "enum", - "name": "OAuthStatus", - "doc": "* `PENDING`: the user has started authorizing, but not yet finished\n* `ACTIVE`: the token should work\n* `DENIED`: the user declined the authorization\n* `EXPIRED`: the token used to work, but now it doesn't\n* `REVOKED`: the user has explicitly revoked the token", - "symbols": ["PENDING", "ACTIVE", "DENIED", "EXPIRED", "REVOKED"] - } - }, - { - "name": "userId", - "doc": "Twitter's numeric ID for this user", - "type": "long" - }, - { - "name": "screenName", - "doc": "The twitter username for this account (can be changed by the user)", - "type": "string" - }, - { - "name": "oauthToken", - "doc": "The OAuth token for this Twitter account", - "type": "string" - }, - { - "name": "oauthTokenSecret", - "doc": "The OAuth secret, used for signing requests on behalf of this Twitter account. `null` whilst the OAuth flow is not yet complete.", - "type": ["null", "string"] - }, - { - "name": "dateAuthorized", - "doc": "Timestamp (milliseconds since epoch) when the user last authorized this Twitter account", - "type": "long" - } - ] - } - } - }, - { - "name": "toDoItems", - "doc": "The top-level items in the user's to-do list", - "type": { - "type": "array", - "items": { - "type": "record", - "name": "ToDoItem", - "doc": "A record is one node in a To-Do item tree (every record can contain nested sub-records).", - "fields": [ - { - "name": "status", - "doc": "User-selected state for this item (e.g. whether or not it is marked as done)", - "type": { - "type": "enum", - "name": "ToDoStatus", - "doc": "* `HIDDEN`: not currently visible, e.g. because it becomes actionable in future\n* `ACTIONABLE`: appears in the current to-do list\n* `DONE`: marked as done, but still appears in the list\n* `ARCHIVED`: marked as done and no longer visible\n* `DELETED`: not done and removed from list (preserved for undo purposes)", - "symbols": ["HIDDEN", "ACTIONABLE", "DONE", "ARCHIVED", "DELETED"] - } - }, - { - "name": "title", - "doc": "One-line summary of the item", - "type": "string" - }, - { - "name": "description", - "doc": "Detailed description (may contain HTML markup)", - "type": ["null", "string"] - }, - { - "name": "snoozeDate", - "doc": "Timestamp (milliseconds since epoch) at which the item should go from `HIDDEN` to `ACTIONABLE` status", - "type": ["null", "long"] - }, - { - "name": "subItems", - "doc": "List of children of this to-do tree node", - "type": { - "type": "array", - "items": "ToDoItem" - } - } - ] - } - } - } - ] -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc deleted file mode 100644 index 102641b44..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc +++ /dev/null @@ -1,172 +0,0 @@ -{ - "type": "record", - "name": "User", - "namespace": "com.example.avro", - "doc": "This is a user record in a fictitious to-do-list management app. It supports arbitrary grouping and nesting of items, and allows you to add items by email or by tweeting.\n\nNote this app doesn't actually exist. The schema is just a demo for [Avrodoc](https://github.com/ept/avrodoc)!", - "fields": [ - {"name": "firstname", "type": "string"}, - {"name": "lastname", "type": "string"}, - { - "name": "address", - "type": { - "type" : "record", - "name" : "AddressUSRecord", - "fields" : [ - {"name": "streetaddress_DasH_1", "type": "string"}, - {"name": "city", "type": "string"} - ] - } - }, - { - "name": "id", - "doc": "System-assigned numeric user ID. Cannot be changed by the user.", - "type": "int" - }, - { - "name": "username", - "doc": "The username chosen by the user. Can be changed by the user.", - "type": "string" - }, - { - "name": "passwordHash", - "doc": "The user's password, hashed using [scrypt](http://www.tarsnap.com/scrypt.html).", - "type": "string" - }, - { - "name": "signupDate", - "doc": "Timestamp (milliseconds since epoch) when the user signed up", - "type": "long" - }, - { - "name": "email_DoT_Addresses", - "doc": "All email addresses on the user's account", - "type": { - "type": "array", - "items": { - "type": "record", - "name": "EmailAddress", - "doc": "Stores details about an email address that a user has associated with their account.", - "fields": [ - { - "name": "address", - "doc": "The email address, e.g. `foo@example.com`", - "type": "string" - }, - { - "name": "verified", - "doc": "true if the user has clicked the link in a confirmation email to this address.", - "type": "boolean", - "default": false - }, - { - "name": "dateAdded", - "doc": "Timestamp (milliseconds since epoch) when the email address was added to the account.", - "type": "long" - }, - { - "name": "dateBounced", - "doc": "Timestamp (milliseconds since epoch) when an email sent to this address last bounced. Reset to null when the address no longer bounces.", - "type": ["null", "long"] - } - ] - } - } - }, - { - "name": "twitterAccounts", - "doc": "All Twitter accounts that the user has OAuthed", - "type": { - "type": "array", - "items": { - "type": "record", - "name": "TwitterAccount", - "doc": "Stores access credentials for one Twitter account, as granted to us by the user by OAuth.", - "fields": [ - { - "name": "status", - "doc": "Indicator of whether this authorization is currently active, or has been revoked", - "type": { - "type": "enum", - "name": "OAuthStatus", - "doc": "* `PENDING`: the user has started authorizing, but not yet finished\n* `ACTIVE`: the token should work\n* `DENIED`: the user declined the authorization\n* `EXPIRED`: the token used to work, but now it doesn't\n* `REVOKED`: the user has explicitly revoked the token", - "symbols": ["PENDING", "ACTIVE", "DENIED", "EXPIRED", "REVOKED"] - } - }, - { - "name": "userId", - "doc": "Twitter's numeric ID for this user", - "type": "long" - }, - { - "name": "screenName", - "doc": "The twitter username for this account (can be changed by the user)", - "type": "string" - }, - { - "name": "oauthToken", - "doc": "The OAuth token for this Twitter account", - "type": "string" - }, - { - "name": "oauthTokenSecret", - "doc": "The OAuth secret, used for signing requests on behalf of this Twitter account. `null` whilst the OAuth flow is not yet complete.", - "type": ["null", "string"] - }, - { - "name": "dateAuthorized", - "doc": "Timestamp (milliseconds since epoch) when the user last authorized this Twitter account", - "type": "long" - } - ] - } - } - }, - { - "name": "toDoItems", - "doc": "The top-level items in the user's to-do list", - "type": { - "type": "array", - "items": { - "type": "record", - "name": "ToDoItem", - "doc": "A record is one node in a To-Do item tree (every record can contain nested sub-records).", - "fields": [ - { - "name": "status", - "doc": "User-selected state for this item (e.g. whether or not it is marked as done)", - "type": { - "type": "enum", - "name": "ToDoStatus", - "doc": "* `HIDDEN`: not currently visible, e.g. because it becomes actionable in future\n* `ACTIONABLE`: appears in the current to-do list\n* `DONE`: marked as done, but still appears in the list\n* `ARCHIVED`: marked as done and no longer visible\n* `DELETED`: not done and removed from list (preserved for undo purposes)", - "symbols": ["HIDDEN", "ACTIONABLE", "DONE", "ARCHIVED", "DELETED"] - } - }, - { - "name": "title_DasH_long", - "doc": "One-line summary of the item", - "type": "string" - }, - { - "name": "description", - "doc": "Detailed description (may contain HTML markup)", - "type": ["null", "string"] - }, - { - "name": "snoozeDate", - "doc": "Timestamp (milliseconds since epoch) at which the item should go from `HIDDEN` to `ACTIONABLE` status", - "type": ["null", "long"] - }, - { - "name": "subItems", - "doc": "List of children of this to-do tree node", - "type": { - "type": "array", - "items": "ToDoItem" - } - } - ] - } - } - } - ] -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc deleted file mode 100644 index b9aac36f9..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc +++ /dev/null @@ -1,26 +0,0 @@ -{ - "type" : "record", - "name" : "VPNActEvent", - "namespace" : "com.ericsson.apex.domains.vpn.events", - "fields" : [ - {"name": "nameSpace", "type": "string"}, - {"name": "name", "type": "string"}, - {"name": "version", "type": "string"}, - {"name": "source", "type": "string"}, - {"name": "target", "type": "string"}, - {"name": "LinkMap", "type": { - "type" : "record", - "name" : "LinkMap", - "namespace" : "com.ericsson.apex.domains.vpn", - "fields" : [ ] - } - }, - {"name": "CustomerMap", "type": { - "type" : "record", - "name" : "CustomerMap", - "namespace" : "com.ericsson.apex.domains.vpn", - "fields" : [ ] - } - } - ] -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc deleted file mode 100644 index 5936bb21f..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc +++ /dev/null @@ -1,34 +0,0 @@ -{ - "type" : "record", - "name" : "VPNActEvent", - "namespace" : "com.ericsson.apex.domains.vpn.events", - "fields" : [ - {"name": "nameSpace", "type": "string"}, - {"name": "name", "type": "string"}, - {"name": "version", "type": "string"}, - {"name": "source", "type": "string"}, - {"name": "target", "type": "string"}, - {"name": "LinkMap", "type": { - "type" : "record", - "name" : "LinkMap", - "namespace" : "com.ericsson.apex.domains.vpn", - "fields" : [ ] - } - }, - {"name": "CustomerMap", "type": { - "type" : "record", - "name" : "CustomerMap", - "namespace" : "com.ericsson.apex.domains.vpn", - "fields" : [ ] - } - }, - {"name": "CustomerMap1", "type": "com.ericsson.apex.domains.vpn.CustomerMap"}, - { - "name" : "CustomerMapArray", - "type": { - "type": "array", - "items": "com.ericsson.apex.domains.vpn.CustomerMap" - } - } - ] -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/UnionExample.avsc b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/UnionExample.avsc deleted file mode 100644 index 96b6050fb..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/avsc/UnionExample.avsc +++ /dev/null @@ -1,30 +0,0 @@ -{ - "namespace": "example.avro", - "type": "record", - "name": "User", - "fields": [ - { - "name": "name", - "type": "string" - }, - { - "name": "favourite_number", - "type": [ - "null", - "int" - ] - }, - { - "name": "favourite_colour", - "type": [ - "null", - "string" - ] - }, - { - "name": "favourite_group", - "type": ["null", "string"], - "default": "null" - } - ] -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4Policy.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4Policy.json deleted file mode 100644 index 25ca3af8a..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4Policy.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "model-name": "service-instance", - "generic-vnf": { - "vnf-id": "de7cc3ab-0212-47df-9e64-da1c79234deb", - "vnf-name": "ZRDM2MMEX39", - "vnf-type": "vMME Svc Jul 14/vMME VF Jul 14 1", - "service-id": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", - "orchestration-status": "active", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1503082370097", - "model-invariant-id": "82194af1-3c2c-485a-8f44-420e22a9eaa4", - "model-version-id": "46b92144-923a-4d20-b85a-3cbd847668a9" - }, - "extra-properties": { - - } - } -] diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4VNF.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4VNF.json deleted file mode 100644 index 41cfc5c17..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponse4VNF.json +++ /dev/null @@ -1,302 +0,0 @@ -[ - { - "model-name": "vFW", - "generic-vnf": { - "vnf-id": "vFirewall_demo_app", - "vnf-name": "vFirewall_demo_app", - "vnf-type": "vFW", - "service-id": "vFirewall_demo_app", - "orchestration-status": "running", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509456799110", - "model-invariant-id": "vFirewall", - "model-version-id": "vFW" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "vserver": { - "vserver-id": "5b06cf36-40a0-4bcb-bde9-849aa4702d67", - "vserver-name": "vFW", - "vserver-name2": "vFW", - "prov-status": "Running", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/466979b815b5415ba14ada713e6e1846/servers/5b06cf36-40a0-4bcb-bde9-849aa4702d67", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509047869791" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "vnfc": { - "vnfc-name": "VNFC_vGMUX_demo_app2", - "nfc-naming-code": "vGMUXCODE2", - "nfc-function": "vGMUX", - "prov-status": "Running", - "orchestration-status": "Error", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509407048855" - }, - "extra-properties": { - - } - }, - { - "tenant": { - "tenant-id": "466979b815b5415ba14ada713e6e1846", - "tenant-name": "Integration", - "resource-version": "1508920100541" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "cloud-region": { - "cloud-owner": "pod25", - "cloud-region-id": "RegionOne", - "identity-url": "http://10.12.25.2:5000/v3", - "sriov-automation": false, - "resource-version": "1509048416263" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "esr-system-info": { - "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29", - "system-name": "example-system-name-val-29070", - "type": "example-type-val-85254", - "vendor": "example-vendor-val-94515", - "version": "example-version-val-71880", - "service-url": "http://10.12.25.2:5000/v3", - "user-name": "demo", - "password": "onapdemo", - "system-type": "VIM", - "ssl-cacert": "example-ssl-cacert-val-75021", - "ssl-insecure": true, - "ip-address": "example-ip-address-val-44431", - "port": "example-port-val-93234", - "cloud-domain": "Default", - "default-tenant": "Integration", - "resource-version": "1508920101033" - }, - "extra-properties": { - - } - } - ] - } - } - ] - } - } - ] - } - }, - { - "vserver": { - "vserver-id": "0c52905c-f682-42cf-bd52-e7f8953e80e3", - "vserver-name": "vFW", - "vserver-name2": "vFW", - "prov-status": "Running", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/466979b815b5415ba14ada713e6e1846/servers/0c52905c-f682-42cf-bd52-e7f8953e80e3", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509047548567" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "vnfc": { - "vnfc-name": "VNFC_vGMUX_demo_app3", - "nfc-naming-code": "vGMUXCODE3", - "nfc-function": "vGMUX", - "prov-status": "Running", - "orchestration-status": "Running", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509041912808" - }, - "extra-properties": { - - } - }, - { - "tenant": { - "tenant-id": "466979b815b5415ba14ada713e6e1846", - "tenant-name": "Integration", - "resource-version": "1508920100541" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "cloud-region": { - "cloud-owner": "pod25", - "cloud-region-id": "RegionOne", - "identity-url": "http://10.12.25.2:5000/v3", - "sriov-automation": false, - "resource-version": "1509048416263" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "esr-system-info": { - "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29", - "system-name": "example-system-name-val-29070", - "type": "example-type-val-85254", - "vendor": "example-vendor-val-94515", - "version": "example-version-val-71880", - "service-url": "http://10.12.25.2:5000/v3", - "user-name": "demo", - "password": "onapdemo", - "system-type": "VIM", - "ssl-cacert": "example-ssl-cacert-val-75021", - "ssl-insecure": true, - "ip-address": "example-ip-address-val-44431", - "port": "example-port-val-93234", - "cloud-domain": "Default", - "default-tenant": "Integration", - "resource-version": "1508920101033" - }, - "extra-properties": { - - } - } - ] - } - } - ] - } - } - ] - } - }, - { - "vserver": { - "vserver-id": "33e16e02-098a-4f4e-a37f-b4e0307596c0", - "vserver-name": "vFW", - "vserver-name2": "vFW", - "prov-status": "Running", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/466979b815b5415ba14ada713e6e1846/servers/33e16e02-098a-4f4e-a37f-b4e0307596c0", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509047285114" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "vnfc": { - "vnfc-name": "vnfc-related-to-vserver-example", - "nfc-naming-code": "example-nfc-naming-code-val-78172", - "nfc-function": "example-nfc-function-val-56352", - "prov-status": "example-prov-status-val-10699", - "orchestration-status": "example-orchestration-status-val-68896", - "ipaddress-v4-oam-vip": "example-ipaddress-v4-oam-vip-val-71483", - "in-maint": true, - "is-closed-loop-disabled": true, - "group-notation": "example-group-notation-val-31912", - "resource-version": "1508800709772" - }, - "extra-properties": { - - } - }, - { - "vnfc": { - "vnfc-name": "VNFC_vGMUX_demo_app", - "nfc-naming-code": "vGMUXCODE", - "nfc-function": "vGMUX", - "prov-status": "Running", - "orchestration-status": "Running", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1509041573965" - }, - "extra-properties": { - - } - }, - { - "tenant": { - "tenant-id": "466979b815b5415ba14ada713e6e1846", - "tenant-name": "Integration", - "resource-version": "1508920100541" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "cloud-region": { - "cloud-owner": "pod25", - "cloud-region-id": "RegionOne", - "identity-url": "http://10.12.25.2:5000/v3", - "sriov-automation": false, - "resource-version": "1509048416263" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "esr-system-info": { - "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29", - "system-name": "example-system-name-val-29070", - "type": "example-type-val-85254", - "vendor": "example-vendor-val-94515", - "version": "example-version-val-71880", - "service-url": "http://10.12.25.2:5000/v3", - "user-name": "demo", - "password": "onapdemo", - "system-type": "VIM", - "ssl-cacert": "example-ssl-cacert-val-75021", - "ssl-insecure": true, - "ip-address": "example-ip-address-val-44431", - "port": "example-port-val-93234", - "cloud-domain": "Default", - "default-tenant": "Integration", - "resource-version": "1508920101033" - }, - "extra-properties": { - - } - } - ] - } - } - ] - } - } - ] - } - } - ] - } - } -] diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponseExample.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponseExample.json deleted file mode 100644 index a1a1e19bc..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/AAIResponseExample.json +++ /dev/null @@ -1,209 +0,0 @@ -{ - "inventory-response-item": [ - { - "vserver": { - "vserver-id": "6ed3642c-f7a1-4a7c-9290-3d51fe1531eb", - "vserver-name": "zdfw1lb01lb02", - "vserver-name2": "zdfw1lb01lb02", - "prov-status": "ACTIVE", - "vserver-selflink": "http://10.12.25.2:8774/v2.1/41d6d38489bd40b09ea8a6b6b852dcbd/servers/6ed3642c-f7a1-4a7c-9290-3d51fe1531eb", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1510606403522" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "model-name": "vLoadBalancer", - "generic-vnf": { - "vnf-id": "db373a8d-f7be-4d02-8ac8-6ca4c305d144", - "vnf-name": "Vfmodule_vLB1113", - "vnf-type": "vLoadBalancer-1106/vLoadBalancer 0", - "service-id": "66f157fc-4148-4880-95f5-e120677e98d1", - "prov-status": "PREPROV", - "orchestration-status": "Created", - "in-maint": false, - "is-closed-loop-disabled": false, - "resource-version": "1510604011851", - "model-invariant-id": "cee050ed-92a5-494f-ab04-234307a846dc", - "model-version-id": "fd65becc-6b2c-4fe8-ace9-cc29db9a3da2", - "model-customization-id": "1983c783-444f-4e79-af3a-85e5d49628f3", - "nf-type": "", - "nf-function": "", - "nf-role": "", - "nf-naming-code": "" - }, - "extra-properties": { - "extra-property": [ - { - "property-name": "model-ver.model-version-id", - "property-value": "fd65becc-6b2c-4fe8-ace9-cc29db9a3da2" - }, - { - "property-name": "model-ver.model-name", - "property-value": "vLoadBalancer" - }, - { - "property-name": "model.model-type", - "property-value": "resource" - }, - { - "property-name": "model.model-invariant-id", - "property-value": "cee050ed-92a5-494f-ab04-234307a846dc" - }, - { - "property-name": "model-ver.model-version", - "property-value": "1.0" - } - ] - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "model-name": "vLoadBalancer-1106", - "service-instance": { - "service-instance-id": "3b12f31f-8f2d-4f5c-b875-61ff1194b941", - "service-instance-name": "vLoadBalancer-1113", - "model-invariant-id": "1321d60d-f7ff-4300-96c2-6bf0b3268b7a", - "model-version-id": "732d4692-4b97-46f9-a996-0b3339e88c50", - "resource-version": "1510603936425" - }, - "extra-properties": { - "extra-property": [ - { - "property-name": "model-ver.model-version-id", - "property-value": "732d4692-4b97-46f9-a996-0b3339e88c50" - }, - { - "property-name": "model-ver.model-name", - "property-value": "vLoadBalancer-1106" - }, - { - "property-name": "model.model-type", - "property-value": "service" - }, - { - "property-name": "model.model-invariant-id", - "property-value": "1321d60d-f7ff-4300-96c2-6bf0b3268b7a" - }, - { - "property-name": "model-ver.model-version", - "property-value": "1.0" - } - ] - } - }, - { - "model-name": "Vloadbalancer..base_vlb..module-0", - "vf-module": { - "vf-module-id": "e6b3e3eb-34e1-4c00-b8c1-2a4fbe479b12", - "vf-module-name": "Vfmodule_vLB1113-1", - "heat-stack-id": "Vfmodule_vLB1113-1/3dd6d900-772f-4fcc-a0cb-e250ab2bb4db", - "orchestration-status": "active", - "is-base-vf-module": true, - "resource-version": "1510604612557", - "model-invariant-id": "6d760188-9a24-451a-b05b-e08b86cb94f2", - "model-version-id": "93facad9-55f2-4fe0-9574-814c2bc2d071", - "model-customization-id": "93fd5bd4-8051-4074-8530-c0c504604df5", - "module-index": 0 - }, - "extra-properties": { - "extra-property": [ - { - "property-name": "model-ver.model-version-id", - "property-value": "93facad9-55f2-4fe0-9574-814c2bc2d071" - }, - { - "property-name": "model-ver.model-name", - "property-value": "Vloadbalancer..base_vlb..module-0" - }, - { - "property-name": "model.model-type", - "property-value": "resource" - }, - { - "property-name": "model.model-invariant-id", - "property-value": "6d760188-9a24-451a-b05b-e08b86cb94f2" - }, - { - "property-name": "model-ver.model-version", - "property-value": "1" - } - ] - } - }, - { - "model-name": "Vloadbalancer..dnsscaling..module-1", - "vf-module": { - "vf-module-id": "dummy_db373a8d-f7be-4d02-8ac8-6ca4c305d144", - "vf-module-name": "dummy_db373a8d-f7be-4d02-8ac8-6ca4c305d144", - "is-base-vf-module": false, - "resource-version": "1510610079687", - "model-invariant-id": "356a1cff-71f2-4086-9980-a2927ce11c1c", - "model-version-id": "6b93d804-cfc8-4be3-92cc-9336d135859a" - }, - "extra-properties": { - "extra-property": [ - { - "property-name": "model-ver.model-version-id", - "property-value": "6b93d804-cfc8-4be3-92cc-9336d135859a" - }, - { - "property-name": "model-ver.model-name", - "property-value": "Vloadbalancer..dnsscaling..module-1" - }, - { - "property-name": "model.model-type", - "property-value": "resource" - }, - { - "property-name": "model.model-invariant-id", - "property-value": "356a1cff-71f2-4086-9980-a2927ce11c1c" - }, - { - "property-name": "model-ver.model-version", - "property-value": "1" - } - ] - } - } - ] - } - }, - { - "tenant": { - "tenant-id": "41d6d38489bd40b09ea8a6b6b852dcbd", - "tenant-name": "Integration-SB-00", - "resource-version": "1509587770200" - }, - "extra-properties": { - - }, - "inventory-response-items": { - "inventory-response-item": [ - { - "cloud-region": { - "cloud-owner": "CloudOwner", - "cloud-region-id": "RegionOne", - "cloud-type": "SharedNode", - "owner-defined-type": "OwnerType", - "cloud-region-version": "v1", - "cloud-zone": "CloudZone", - "sriov-automation": false, - "resource-version": "1509587770092" - }, - "extra-properties": { - - } - } - ] - } - } - ] - } - } - ] -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json deleted file mode 100644 index 9ad632a8f..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json +++ /dev/null @@ -1,13 +0,0 @@ -[ { - "streetaddress" : "1600 Pennsylvania Avenue", - "city" : "Washington DC" -}, { - "streetaddress" : "Somewhere", - "city" : "Over the rainbow" -}, { - "streetaddress" : "221 B Baker St.", - "city" : "London" -}, { - "streetaddress" : "Wayne Manor", - "city" : "Gotham City" -} ] \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json deleted file mode 100644 index 8878e547a..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json +++ /dev/null @@ -1 +0,0 @@ -[ ] \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json deleted file mode 100644 index ca12244ee..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json +++ /dev/null @@ -1 +0,0 @@ -[ 9223372036854775807, -3, -2, 1, -9223372036854775808, -67890, 5, 0 ] \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json deleted file mode 100644 index 8878e547a..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json +++ /dev/null @@ -1 +0,0 @@ -[ ] \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad0.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad0.json deleted file mode 100644 index d1218ca59..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad0.json +++ /dev/null @@ -1 +0,0 @@ -"TWEED" \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad1.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad1.json deleted file mode 100644 index 67b3fe5c7..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleBad1.json +++ /dev/null @@ -1 +0,0 @@ -"Hearts" \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleHearts.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleHearts.json deleted file mode 100644 index 92bd68a7e..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleHearts.json +++ /dev/null @@ -1 +0,0 @@ -"HEARTS" \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleNull.json deleted file mode 100644 index ec747fa47..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/EnumExampleNull.json +++ /dev/null @@ -1 +0,0 @@ -null \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad0.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad0.json deleted file mode 100644 index f0251f122..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad0.json +++ /dev/null @@ -1 +0,0 @@ -"BADBAD" \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad1.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad1.json deleted file mode 100644 index 687d14210..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleBad1.json +++ /dev/null @@ -1 +0,0 @@ -"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0" \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleGood.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleGood.json deleted file mode 100644 index 846002e51..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleGood.json +++ /dev/null @@ -1 +0,0 @@ -"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleNull.json deleted file mode 100644 index ec747fa47..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/FixedExampleNull.json +++ /dev/null @@ -1 +0,0 @@ -null \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/HealthCheckEvent.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/HealthCheckEvent.json deleted file mode 100644 index 4233f3b57..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/HealthCheckEvent.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "input": { - "action": "HealthCheck", - "action-identifiers": { - "vnf-id": "49414df5-3482-4fd8-9952-c463dff2770b" - }, - "common-header": { - "request-id": "afr-request3", - "originator-id": "AFR", - "api-ver": "2.15", - "sub-request-id": "AFR-subrequest", - "timestamp": "2017-11-06T15:15:18.97Z", - "flags": { - "ttl": "10000", - "force": "TRUE", - "mode": "EXCLUSIVE" - } - }, - "payload": "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\",\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}" - } -} - diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressFull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressFull.json deleted file mode 100644 index 2a1911445..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressFull.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "address0" : { - "streetaddress" : "1600 Pennsylvania Avenue", - "city" : "Washington DC" - }, - "address1" : { - "streetaddress" : "Somewhere", - "city" : "Over the rainbow" - }, - "address2" : { - "streetaddress" : "221 B Baker St.", - "city" : "London" - }, - "address3" : { - "streetaddress" : "Wayne Manor", - "city" : "Gotham City" - } -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json deleted file mode 100644 index fa23c8328..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "address.0" : { - "street-address" : "1600 Pennsylvania Avenue", - "the.city" : "Washington DC" - }, - "address.1" : { - "street-address" : "Somewhere", - "the.city" : "Over the rainbow" - }, - "address.2" : { - "street-address" : "221 B Baker St.", - "the.city" : "London" - }, - "address.3" : { - "street-address" : "Wayne Manor", - "the.city" : "Gotham City" - } -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressNull.json deleted file mode 100644 index 9e26dfeeb..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleAddressNull.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongFull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongFull.json deleted file mode 100644 index f94a4f600..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongFull.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "key04" : 9223372036854775807, - "key03" : -3, - "key02" : -2, - "key01" : 1, - "key07" : -9223372036854775808, - "key06" : -67890, - "key05" : 5, - "key00" : 0 -} diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongNull.json deleted file mode 100644 index 9e26dfeeb..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/MapExampleLongNull.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleFull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleFull.json deleted file mode 100644 index d4fbf106a..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleFull.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "firstname" : "Liam", - "lastname" : "Fallon", - "address" : { - "streetaddress" : "Somewhere", - "city" : "Over the rainbow" - }, - "id" : 1497, - "username" : "eeilfn", - "passwordHash" : "gobbledygook", - "signupDate" : 894614400, - "emailAddresses" : [ { - "address" : "sean@citizen.ie", - "verified" : true, - "dateAdded" : 1495805460, - "dateBounced" : { - "long" : 1495805460 - } - } ], - "twitterAccounts" : [ { - "status" : "ACTIVE", - "userId" : 12345, - "screenName" : "Zooby", - "oauthToken" : "ZoobyOToken", - "oauthTokenSecret" : { - "string" : "ZoobyOTokenSecret" - }, - "dateAuthorized" : 149580546 - } ], - "toDoItems" : [ { - "status" : "DONE", - "title" : "fierce important thing", - "description" : { - "string" : "Description of fierce important thing" - }, - "snoozeDate" : { - "long" : 149580567 - }, - "subItems" : [ ] - } ] -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json deleted file mode 100644 index f40075e27..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "firstname" : "Liam", - "lastname" : "Fallon", - "address" : { - "streetaddress-1" : "Somewhere", - "city" : "Over the rainbow" - }, - "id" : 1497, - "username" : "eeilfn", - "passwordHash" : "gobbledygook", - "signupDate" : 894614400, - "email.Addresses" : [ { - "address" : "sean@citizenie", - "verified" : true, - "dateAdded" : 1495805460, - "dateBounced" : { - "long" : 1495805460 - } - } ], - "twitterAccounts" : [ { - "status" : "ACTIVE", - "userId" : 12345, - "screenName" : "Zooby", - "oauthToken" : "ZoobyOToken", - "oauthTokenSecret" : { - "string" : "ZoobyOTokenSecret" - }, - "dateAuthorized" : 149580546 - } ], - "toDoItems" : [ { - "status" : "DONE", - "title-long" : "fierce important thing", - "description" : { - "string" : "Description of fierce important thing" - }, - "snoozeDate" : { - "long" : 149580567 - }, - "subItems" : [ ] - } ] -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleNull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleNull.json deleted file mode 100644 index 03eef6c05..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleNull.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "firstname" : "", - "lastname" : "", - "address" : { - "streetaddress" : "", - "city" : "" - }, - "id" : 0, - "username" : "", - "passwordHash" : "", - "signupDate" : 0, - "emailAddresses" : [ ], - "twitterAccounts" : [ ], - "toDoItems" : [ ] -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json deleted file mode 100644 index 7e4da3391..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "nameSpace" : "com.ericsson.apex.domains.vpn.events", - "name" : "VPNTriggerEvent", - "version" : "0.0.1", - "source" : "VPNSLA", - "target" : "Apex", - "LinkMap" : { }, - "CustomerMap" : { } -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleAllFields.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleAllFields.json deleted file mode 100644 index 88299e3a4..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleAllFields.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name" : "Ben", - "favourite_number" : 7, - "favourite_colour" : "red", - "favourite_group" : "Zooby" -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleNullField.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleNullField.json deleted file mode 100644 index 4fd33a6eb..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleNullField.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Alyssa", - "favourite_number": 256, - "favourite_colour": null, - "favourite_group": "U2" -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json deleted file mode 100644 index f62d25b31..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Claire", - "favourite_number": 123, - "favourite_colour": null -} \ No newline at end of file diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/logback-test.xml b/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/logback-test.xml deleted file mode 100644 index 3dd11e9cb..000000000 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/test/resources/logback-test.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - Apex - - - - - - - %d %contextName [%t] %level %logger{36} - %msg%n - - - - - - - - - - - - - - - - - ${LOG_DIR}/apex.log - - %d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full} - - - - - ${LOG_DIR}/apex_ctxt.log - - %d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full} - - - - - - - - - - - - - - - diff --git a/plugins/plugins-context/context-schema/pom.xml b/plugins/plugins-context/context-schema/pom.xml deleted file mode 100644 index d60cb5570..000000000 --- a/plugins/plugins-context/context-schema/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.plugins.plugins-context - plugins-context - 2.0.0-SNAPSHOT - - - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema - pom - - ${project.artifactId} - Plugins for 3pps that handle context schemas - - context-schema-avro - - diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml new file mode 100644 index 000000000..e8fe62565 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution + 2.0.0-SNAPSHOT + + + plugins-context-distribution-hazelcast + ${project.artifactId} + [${project.parent.artifactId}] Plugin for distribution using Hazelcast + + + + com.hazelcast + hazelcast + ${version.hazelcast} + + + org.onap.policy.apex-pdp.context + context-test-utils + ${project.version} + test + + + diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java new file mode 100644 index 000000000..2b17b17cf --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributor.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.distribution.hazelcast; + +import java.util.Map; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.context.impl.distribution.AbstractDistributor; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +import com.hazelcast.core.Hazelcast; +import com.hazelcast.core.HazelcastInstance; + +/** + * This context distributor distributes context across threads in multiple JVMs on multiple hosts. + * It uses hazelcast to distribute maps. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class HazelcastContextDistributor extends AbstractDistributor { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(HazelcastContextDistributor.class); + + // The hazelcast instance for distributing context for this JVM + private static HazelcastInstance hazelcastInstance = null; + + /** + * Create an instance of a Hazelcast Context Distributor. + * + * @throws ContextException On errors creating the context distributor + */ + public HazelcastContextDistributor() throws ContextException { + super(); + LOGGER.entry("HazelcastContextDistributor()"); + + LOGGER.exit("HazelcastContextDistributor()"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.context.impl.distribution.AbstractContextDistributor#init(org.onap. + * policy.apex.model.basicmodel.concepts.AxArtifactKey) + */ + @Override + public void init(final AxArtifactKey key) throws ContextException { + LOGGER.entry("init(" + key + ")"); + + super.init(key); + + // Create the hazelcast instance if it does not already exist + if (hazelcastInstance == null) { + hazelcastInstance = Hazelcast.newHazelcastInstance(); + } + + LOGGER.exit("init(" + key + ")"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.context.impl.distribution.AbstractContextDistributor# + * getContextAlbumMap(org.onap.policy.apex.core.model.concepts.AxArtifactKey) + */ + @Override + public Map getContextAlbumMap(final AxArtifactKey contextAlbumKey) { + // Get the map from Hazelcast + LOGGER.info("HazelcastContextDistributor: create album: " + contextAlbumKey.getID()); + return hazelcastInstance.getMap(contextAlbumKey.getID()); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.context.impl.distribution.AbstractContextDistributor#shutdown() + */ + @Override + public void shutdown() { + // Shut down the hazelcast instance + if (hazelcastInstance != null) { + hazelcastInstance.shutdown(); + } + hazelcastInstance = null; + } +} diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java new file mode 100644 index 000000000..027aeecde --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Implements the Hazelcast context distributor for distribution + * of Apex context across JVMs. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.plugins.context.distribution.hazelcast; diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample new file mode 100644 index 000000000..5f6c1b005 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/main/resources/hazelcast/hazelcast.xml.sample @@ -0,0 +1,55 @@ + + + + + + ApexHazelcastGroup + ApexHazelcastGroupPassword + + + 5706 + + + 224.2.2.10 + 54327 + + + 127.0.0.1 + + + + + 127.0.0.* + + + + true + slf4j + + false + 60 + + + 16 + + diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java new file mode 100644 index 000000000..c999c95f0 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-hazelcast/src/test/java/org/onap/policy/apex/plugins/context/distribution/hazelcast/HazelcastContextDistributorTest.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.distribution.hazelcast; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.test.distribution.ContextAlbumUpdate; +import org.onap.policy.apex.context.test.distribution.ContextInstantiation; +import org.onap.policy.apex.context.test.distribution.ContextUpdate; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class HazelcastContextDistributorTest { + private static final String HAZEL_CAST_PLUGIN_CLASS = HazelcastContextDistributor.class.getCanonicalName(); + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(HazelcastContextDistributorTest.class); + + + @Test + public void testContextAlbumUpdateHazelcast() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextAlbumUpdateHazelcast test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS); + new ContextAlbumUpdate().testContextAlbumUpdate(); + + logger.debug("Ran testContextAlbumUpdateHazelcast test"); + } + + @Test + public void testContextInstantiationHazelcast() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextInstantiationHazelcast test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS); + new ContextInstantiation().testContextInstantiation(); + + logger.debug("Ran testContextInstantiationHazelcast test"); + } + + @Test + public void testContextUpdateHazelcast() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextUpdateHazelcast test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(HAZEL_CAST_PLUGIN_CLASS); + new ContextUpdate().testContextUpdate(); + + logger.debug("Ran testContextUpdateHazelcast test"); + } + +} diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml new file mode 100644 index 000000000..96ed6e85e --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution + 2.0.0-SNAPSHOT + + + plugins-context-distribution-infinispan + ${project.artifactId} + [${project.parent.artifactId}] Plugin for distribution using Infinispan + + + + org.infinispan + infinispan-core + 9.2.2.Final + + + org.jboss.slf4j + slf4j-jboss-logging + + + + + org.onap.policy.apex-pdp.context + context-test-utils + ${project.version} + test + + + + diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java new file mode 100644 index 000000000..9361d0b4c --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributor.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.distribution.infinispan; + +import java.util.Map; + +import org.infinispan.Cache; +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.context.impl.distribution.AbstractDistributor; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.service.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This context distributor distributes context across threads in multiple JVMs on multiple hosts. + * It uses Infinispan to distribute maps. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class InfinispanContextDistributor extends AbstractDistributor { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(InfinispanContextDistributor.class); + + // The infinispan manager for distributing context for this JVM + private static InfinispanManager infinispanManager = null; + + /** + * Create an instance of an Infinispan Context Distributor. + * + * @throws ContextException On errors creating the context distributor + */ + public InfinispanContextDistributor() throws ContextException { + LOGGER.entry("InfinispanContextDistributor()"); + + LOGGER.exit("InfinispanContextDistributor()"); + } + + /* + * (non-Javadoc) + * + * @see + * com.ericsson.apex.context.impl.distribution.AbstractContextDistributor#init(com.ericsson.apex + * .model.basicmodel.concepts.AxArtifactKey) + */ + @Override + public void init(final AxArtifactKey key) throws ContextException { + LOGGER.entry("init(" + key + ")"); + + super.init(key); + + // Create the infinispan manager if it does not already exist + if (infinispanManager == null) { + // Get the parameters from the parameter service + final InfinispanDistributorParameters parameters = + ParameterService.getParameters(InfinispanDistributorParameters.class); + + LOGGER.debug("initiating Infinispan with the parameters: " + parameters); + + // Create the manager + infinispanManager = new InfinispanManager(parameters); + } + + LOGGER.exit("init(" + key + ")"); + } + + /* + * (non-Javadoc) + * + * @see com.ericsson.apex.core.context.impl.distribution.AbstractContextDistributor# + * getContextAlbumMap(com.ericsson.apex.core.model.concepts.AxArtifactKey) + */ + @Override + public Map getContextAlbumMap(final AxArtifactKey contextAlbumKey) { + LOGGER.info("InfinispanContextDistributor: create album: " + contextAlbumKey.getID()); + + // Get the Cache from Infinispan + final Cache infinispanCache = + infinispanManager.getCacheManager().getCache(contextAlbumKey.getID().replace(':', '_')); + + return infinispanCache; + } + + /* + * (non-Javadoc) + * + * @see com.ericsson.apex.core.context.impl.distribution.AbstractContextDistributor#shutdown() + */ + @Override + public void shutdown() { + // Shut down the infinispan manager + if (infinispanManager != null) { + infinispanManager.shutdown(); + } + infinispanManager = null; + } +} diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java new file mode 100644 index 000000000..d73955224 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanDistributorParameters.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.distribution.infinispan; + +import org.onap.policy.apex.context.parameters.DistributorParameters; +import org.onap.policy.apex.model.basicmodel.service.ParameterService; + +/** + * Distributor parameters for the Infinspan Distributor. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class InfinispanDistributorParameters extends DistributorParameters { + // @formatter:off + + /** The default Infinispan configuration file location. */ + public static final String DEFAULT_INFINISPAN_DISTRIBUTION_CONFIG_FILE = "/infinispan/infinispan.xml"; + + /** The default Infinispan jgroups configuration file location. */ + public static final String DEFAULT_INFINISPAN_DISTRIBUTION_JGROUPS_FILE = null; + + /** The default Infinispan IP stack is IPV4. */ + public static final boolean DEFAULT_INFINISPAN_JAVA_NET_PREFER_IPV4_STACK = true; + + /** The default Infinispan bind address is localhost. */ + public static final String DEFAULT_INFINSPAN_JGROUPS_BIND_ADDRESS = "localhost"; + + // Infinspan configuration file names + private String configFile = DEFAULT_INFINISPAN_DISTRIBUTION_CONFIG_FILE; + private String jgroupsFile = DEFAULT_INFINISPAN_DISTRIBUTION_JGROUPS_FILE; + private boolean preferIPv4Stack = DEFAULT_INFINISPAN_JAVA_NET_PREFER_IPV4_STACK; + private String jGroupsBindAddress = DEFAULT_INFINSPAN_JGROUPS_BIND_ADDRESS; + // @formatter:on + + /** + * The Constructor. + */ + public InfinispanDistributorParameters() { + super(InfinispanDistributorParameters.class.getCanonicalName()); + ParameterService.registerParameters(InfinispanDistributorParameters.class, this); + ParameterService.registerParameters(DistributorParameters.class, this); + } + + /** + * Gets the config file. + * + * @return the config file + */ + public String getConfigFile() { + return configFile; + } + + /** + * Sets the config file. + * + * @param configFile the config file + */ + public void setConfigFile(final String configFile) { + this.configFile = configFile; + } + + /** + * Gets the jgroups file. + * + * @return the jgroups file + */ + public String getJgroupsFile() { + return jgroupsFile; + } + + /** + * Sets the jgroups file. + * + * @param jgroupsFile the jgroups file + */ + public void setJgroupsFile(final String jgroupsFile) { + this.jgroupsFile = jgroupsFile; + } + + /** + * Prefer I pv 4 stack. + * + * @return true, if prefer I pv 4 stack + */ + public boolean preferIPv4Stack() { + return preferIPv4Stack; + } + + /** + * Sets the prefer I pv 4 stack. + * + * @param preferIPv4Stack the prefer I pv 4 stack + */ + public void setPreferIPv4Stack(final boolean preferIPv4Stack) { + this.preferIPv4Stack = preferIPv4Stack; + } + + /** + * Getj groups bind address. + * + * @return the j groups bind address + */ + public String getjGroupsBindAddress() { + return jGroupsBindAddress; + } + + /** + * Setj groups bind address. + * + * @param jGroupsBindAddress the j groups bind address + */ + public void setjGroupsBindAddress(final String jGroupsBindAddress) { + this.jGroupsBindAddress = jGroupsBindAddress; + } + + /* + * (non-Javadoc) + * + * @see com.ericsson.apex.context.parameters.DistributorParameters#toString() + */ + @Override + public String toString() { + return "InfinispanDistributorParameters [configFile=" + configFile + ", jgroupsFile=" + jgroupsFile + + ", preferIPv4Stack=" + preferIPv4Stack + ", jGroupsBindAddress=" + jGroupsBindAddress + "]"; + } +} diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java new file mode 100644 index 000000000..1a2076f10 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.distribution.infinispan; + +import java.io.IOException; + +import org.infinispan.manager.DefaultCacheManager; +import org.infinispan.manager.EmbeddedCacheManager; +import org.onap.policy.apex.context.ContextException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class InfinispanManager holds the Infinispan cache manager for a JVM. + */ +public class InfinispanManager { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(InfinispanManager.class); + + // The Infinispan Cache Manager + private EmbeddedCacheManager cacheManager; + + /** + * Constructor, set up an Infinispan cache manager. + * + * @param infinispanDistributorParameters the infinispan distributor parameters + * @throws ContextException On errors connecting to Infinispan + */ + public InfinispanManager(final InfinispanDistributorParameters infinispanDistributorParameters) + throws ContextException { + LOGGER.entry("Creating Infinispan Manager: " + infinispanDistributorParameters); + + setSystemProperties(infinispanDistributorParameters); + + try { + LOGGER.debug("starting infinispan cache manager using specified configuration . . ."); + cacheManager = new DefaultCacheManager(infinispanDistributorParameters.getConfigFile()); + LOGGER.debug("started infinispan cache manager using specified configuration"); + } catch (final IOException ioException) { + final String errorMessage = + "failed to start infinispan cache manager, no infinispan configuration found on local file system or in classpath, " + + "try setting Infinspan \"configFile\" parameter"; + LOGGER.error(errorMessage); + throw new ContextException(errorMessage, ioException); + } catch (final Exception e) { + LOGGER.error("failed to start infinispan cache manager using specified configuration", e); + throw new ContextException("failed to start infinispan cache manager using specified configuration", e); + } + + // Start the cache manager + cacheManager.start(); + + Runtime.getRuntime().addShutdownHook(new InfinspanManagerShutdownHook()); + + LOGGER.exit("Created Infinispan Manager: " + infinispanDistributorParameters); + } + + /** + * Shutdown the manager. + */ + public void shutdown() { + if (cacheManager == null) { + return; + } + + cacheManager.stop(); + cacheManager = null; + } + + /** + * Get the cache manager. + * + * @return the infinispan cache manager + */ + public EmbeddedCacheManager getCacheManager() { + return cacheManager; + } + + /** + * Set system properties used by Infinispan. + * + * @param infinispanDistributorParameters The parameter values to set are passed as properties + */ + private void setSystemProperties(final InfinispanDistributorParameters infinispanDistributorParameters) { + System.setProperty("java.net.preferIPv4Stack", + Boolean.toString(infinispanDistributorParameters.preferIPv4Stack())); + System.setProperty("jgroups.bind_addr", infinispanDistributorParameters.getjGroupsBindAddress()); + } + + /** + * Private class to implement the shutdown hook for this infinispan manager. + */ + public class InfinspanManagerShutdownHook extends Thread { + /* + * (non-Javadoc) + * + * @see java.lang.Thread#run() + */ + @Override + public void run() { + shutdown(); + } + } +} diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java new file mode 100644 index 000000000..b9ceeb668 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Implements the Infinispan context distributor for + * distribution of APEX context across JVMs. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.plugins.context.distribution.infinispan; diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample new file mode 100644 index 000000000..302eac935 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/main/resources/infinispan/infinispan.xml.sample @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java new file mode 100644 index 000000000..34fa7d439 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/plugins-context-distribution-infinispan/src/test/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanContextDistributorTest.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.policy.apex.plugins.context.distribution.infinispan; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.test.distribution.ContextAlbumUpdate; +import org.onap.policy.apex.context.test.distribution.ContextInstantiation; +import org.onap.policy.apex.context.test.distribution.ContextUpdate; +import org.onap.policy.apex.context.test.distribution.SequentialContextInstantiation; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class InfinispanContextDistributorTest { + private static final XLogger logger = XLoggerFactory.getXLogger(InfinispanContextDistributorTest.class); + + private static final String PLUGIN_CLASS = InfinispanContextDistributor.class.getCanonicalName(); + + @Test + public void testContextAlbumUpdateInfinispan() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextAlbumUpdateInfinispan test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); + new InfinispanDistributorParameters(); + + new ContextAlbumUpdate().testContextAlbumUpdate(); + + logger.debug("Ran testContextAlbumUpdateInfinispan test"); + } + + @Test + public void testContextInstantiationInfinispan() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextInstantiationInfinispan test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); + new InfinispanDistributorParameters(); + + new ContextInstantiation().testContextInstantiation(); + + logger.debug("Ran testContextInstantiationInfinispan test"); + } + + @Test + public void testContextUpdateInfinispan() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextUpdateInfinispan test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); + new InfinispanDistributorParameters(); + + new ContextUpdate().testContextUpdate(); + + logger.debug("Ran testContextUpdateInfinispan test"); + } + + @Test + public void testSequentialContextInstantiationInfinispan() throws ApexModelException, IOException, ApexException { + logger.debug("Running testSequentialContextInstantiationInfinispan test . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(PLUGIN_CLASS); + new InfinispanDistributorParameters(); + + new SequentialContextInstantiation().testSequentialContextInstantiation(); + + logger.debug("Ran testSequentialContextInstantiationInfinispan test"); + } + + +} diff --git a/plugins/plugins-context/plugins-context-distribution/pom.xml b/plugins/plugins-context/plugins-context-distribution/pom.xml new file mode 100644 index 000000000..0433b33f6 --- /dev/null +++ b/plugins/plugins-context/plugins-context-distribution/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context + plugins-context + 2.0.0-SNAPSHOT + + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution + pom + + ${project.artifactId} + Plugins for 3pps that distribute context + + + plugins-context-distribution-hazelcast + plugins-context-distribution-infinispan + + diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml new file mode 100644 index 000000000..cb5a03d24 --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking + 2.0.0-SNAPSHOT + + + plugins-context-locking-curator + ${project.artifactId} + [${project.parent.artifactId}] Plugin for locking using Curator + + + + org.apache.curator + curator-framework + 4.0.1 + + + + org.apache.zookeeper + zookeeper + + + + + org.apache.curator + curator-recipes + 4.0.1 + + + + org.apache.zookeeper + zookeeper + 3.5.4-beta + + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + + + org.apache.curator + curator-recipes + 4.0.1 + + + diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java new file mode 100644 index 000000000..928255031 --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockFacade.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.locking.curator; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; + +import org.apache.curator.framework.recipes.locks.InterProcessMutex; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class provides a facade over the {@link Lock} interface for Curator locks. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class CuratorLockFacade implements Lock { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(CuratorLockFacade.class); + + // The Lock ID + private final String lockId; + + // The mutex used for Curator locking + private final InterProcessMutex lockMutex; + + /** + * Create the lock Facade. + * + * @param lockMutex The lock mutex behind the facade + * @param lockId The ID of the lock + */ + public CuratorLockFacade(final InterProcessMutex lockMutex, final String lockId) { + this.lockId = lockId; + this.lockMutex = lockMutex; + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.Lock#lock() + */ + @Override + public void lock() { + try { + lockMutex.acquire(); + } catch (final Exception e) { + LOGGER.warn("failed to acquire lock for \"" + lockId, e); + } + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.Lock#lockInterruptibly() + */ + @Override + public void lockInterruptibly() throws InterruptedException { + LOGGER.warn("lockInterruptibly() not supported for \"" + lockId); + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.Lock#tryLock() + */ + @Override + public boolean tryLock() { + try { + lockMutex.acquire(); + return true; + } catch (final Exception e) { + LOGGER.warn("failed to acquire lock for \"" + lockId, e); + return false; + } + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.Lock#tryLock(long, java.util.concurrent.TimeUnit) + */ + @Override + public boolean tryLock(final long time, final TimeUnit unit) throws InterruptedException { + try { + lockMutex.acquire(time, unit); + return true; + } catch (final Exception e) { + LOGGER.warn("failed to acquire lock for \"" + lockId, e); + return false; + } + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.Lock#unlock() + */ + @Override + public void unlock() { + try { + lockMutex.release(); + } catch (final Exception e) { + LOGGER.warn("failed to release lock for \"" + lockId, e); + } + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.Lock#newCondition() + */ + @Override + public Condition newCondition() { + LOGGER.warn("newCondition() not supported for \"" + lockId); + return null; + } +} diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java new file mode 100644 index 000000000..477a010fa --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.locking.curator; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReadWriteLock; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.state.ConnectionState; +import org.apache.curator.framework.state.ConnectionStateListener; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.curator.utils.CloseableUtils; +import org.apache.zookeeper.CreateMode; +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.context.impl.locking.AbstractLockManager; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.service.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class CuratorLockManager manages the Curator interface towards Zookeeper for administering + * the Apex Context Album instance locks.. + */ +public class CuratorLockManager extends AbstractLockManager { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(CuratorLockManager.class); + + // The Curator framework used for locking + private CuratorFramework curatorFramework; + + // The address of the Zookeeper server + private String curatorZookeeperAddress; + + /** + * Constructor, set up a lock manager that uses Curator locking. + * + * @throws ContextException On errors connecting to Curator + */ + public CuratorLockManager() throws ContextException { + LOGGER.entry("CuratorLockManager(): setting up the Curator lock manager . . ."); + + LOGGER.exit("CuratorLockManager(): Curator lock manager set up"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.context.impl.locking.AbstractLockManager#init(org.onap.policy.apex. + * model. basicmodel.concepts.AxArtifactKey) + */ + @Override + public void init(final AxArtifactKey key) throws ContextException { + LOGGER.entry("init(" + key + ")"); + + super.init(key); + + // Get the lock manager parameters + final CuratorLockManagerParameters lockParameters = + ParameterService.getParameters(CuratorLockManagerParameters.class); + + // Check if the curator address has been set + curatorZookeeperAddress = lockParameters.getZookeeperAddress(); + if (curatorZookeeperAddress == null || curatorZookeeperAddress.trim().length() == 0) { + LOGGER.warn( + "could not set up Curator locking, check if the curator Zookeeper address parameter is set correctly"); + throw new ContextException( + "could not set up Curator locking, check if the curator Zookeeper address parameter is set correctly"); + } + + // Set up the curator framework we'll use + curatorFramework = CuratorFrameworkFactory.builder().connectString(curatorZookeeperAddress) + .retryPolicy(new ExponentialBackoffRetry(lockParameters.getZookeeperConnectSleepTime(), + lockParameters.getZookeeperContextRetries())) + .build(); + + // Listen for changes on the Curator connection + curatorFramework.getConnectionStateListenable().addListener(new CuratorManagerConnectionStateListener()); + + // Start the framework and specify Ephemeral nodes + curatorFramework.start(); + + // Wait for the connection to be made + try { + curatorFramework.blockUntilConnected( + lockParameters.getZookeeperConnectSleepTime() * lockParameters.getZookeeperContextRetries(), + TimeUnit.MILLISECONDS); + } catch (final InterruptedException e) { + // restore the interrupt status + Thread.currentThread().interrupt(); + LOGGER.warn("could not connect to Zookeeper server at \"" + curatorZookeeperAddress + + "\", wait for connection timed out"); + throw new ContextException("could not connect to Zookeeper server at \"" + curatorZookeeperAddress + + "\", wait for connection timed out"); + } + + if (!curatorFramework.getZookeeperClient().isConnected()) { + LOGGER.warn("could not connect to Zookeeper server at \"" + curatorZookeeperAddress + + "\", see error log for details"); + throw new ContextException("could not connect to Zookeeper server at \"" + curatorZookeeperAddress + + "\", see error log for details"); + } + + // We'll use Ephemeral nodes for locks on the Zookeeper server + curatorFramework.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL); + + LOGGER.exit("init(" + key + "," + lockParameters + ")"); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.context.impl.locking.AbstractLockManager#getReentrantReadWriteLock( + * java.lang.String) + */ + @Override + public ReadWriteLock getReentrantReadWriteLock(final String lockId) throws ContextException { + // Check if the framework is active + if (curatorFramework != null && curatorFramework.getZookeeperClient().isConnected()) { + return new CuratorReentrantReadWriteLock(curatorFramework, "/" + lockId); + } else { + throw new ContextException("creation of lock using Zookeeper server at \"" + curatorZookeeperAddress + + "\", failed, see error log for details"); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.context.LockManager#shutdown() + */ + @Override + public void shutdown() { + if (curatorFramework == null) { + return; + } + CloseableUtils.closeQuietly(curatorFramework); + curatorFramework = null; + } + + /** + * This class is a callback class for state changes on the curator to Zookeeper connection. + */ + private class CuratorManagerConnectionStateListener implements ConnectionStateListener { + + /* + * (non-Javadoc) + * + * @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache. + * curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState) + */ + @Override + public void stateChanged(final CuratorFramework incomngCuratorFramework, final ConnectionState newState) { + // Is the state changed for this curator framework? + if (!incomngCuratorFramework.equals(curatorFramework)) { + return; + } + + LOGGER.info("curator state of client \"" + curatorFramework + "\" connected to \"" + curatorZookeeperAddress + + "\" changed to " + newState); + + if (newState != ConnectionState.CONNECTED) { + shutdown(); + } + } + } +} diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java new file mode 100644 index 000000000..9e8d5d2af --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManagerParameters.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.locking.curator; + +import org.onap.policy.apex.context.parameters.LockManagerParameters; +import org.onap.policy.apex.model.basicmodel.service.ParameterService; + +/** + * Bean class for Curator locking parameters. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class CuratorLockManagerParameters extends LockManagerParameters { + // @formatter:off + /** The default address used to connect to the Zookeeper server. */ + public static final String DEFAULT_ZOOKEEPER_ADDRESS = "localhost:2181"; + + /** The default sleep time to use when connecting to the Zookeeper server. */ + public static final int DEFAULT_ZOOKEEPER_CONNECT_SLEEP_TIME = 1000; + + /** The default number of times to retry failed connections to the Zookeeper server. */ + public static final int DEFAULT_ZOOKEEPER_CONNECT_RETRIES = 3; + + // Curator parameters + private String zookeeperAddress = DEFAULT_ZOOKEEPER_ADDRESS; + private int zookeeperConnectSleepTime = DEFAULT_ZOOKEEPER_CONNECT_SLEEP_TIME; + private int zookeeperContextRetries = DEFAULT_ZOOKEEPER_CONNECT_RETRIES; + // @formatter:on + + /** + * The Constructor. + */ + public CuratorLockManagerParameters() { + super(CuratorLockManagerParameters.class.getCanonicalName()); + ParameterService.registerParameters(CuratorLockManagerParameters.class, this); + } + + /** + * Gets the zookeeper address. + * + * @return the zookeeper address + */ + public String getZookeeperAddress() { + return zookeeperAddress; + } + + /** + * Sets the zookeeper address. + * + * @param zookeeperAddress the zookeeper address + */ + public void setZookeeperAddress(final String zookeeperAddress) { + this.zookeeperAddress = zookeeperAddress; + } + + /** + * Gets the zookeeper connect sleep time. + * + * @return the zookeeper connect sleep time + */ + public int getZookeeperConnectSleepTime() { + return zookeeperConnectSleepTime; + } + + /** + * Sets the zookeeper connect sleep time. + * + * @param zookeeperConnectSleepTime the zookeeper connect sleep time + */ + public void setZookeeperConnectSleepTime(final int zookeeperConnectSleepTime) { + this.zookeeperConnectSleepTime = zookeeperConnectSleepTime; + } + + /** + * Gets the zookeeper context retries. + * + * @return the zookeeper context retries + */ + public int getZookeeperContextRetries() { + return zookeeperContextRetries; + } + + /** + * Sets the zookeeper context retries. + * + * @param zookeeperContextRetries the zookeeper context retries + */ + public void setZookeeperContextRetries(final int zookeeperContextRetries) { + this.zookeeperContextRetries = zookeeperContextRetries; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.context.parameters.LockManagerParameters#toString() + */ + @Override + public String toString() { + return "CuratorLockManagerParameters [zookeeperAddress=" + zookeeperAddress + ", zookeeperConnectSleepTime=" + + zookeeperConnectSleepTime + ", zookeeperContextRetries=" + zookeeperContextRetries + "]"; + } +} diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java new file mode 100644 index 000000000..22bf5e596 --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorReentrantReadWriteLock.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.locking.curator; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock; + +/** + * This class maps a Curator {@link InterProcessReadWriteLock} to a Java {@link ReadWriteLock}. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class CuratorReentrantReadWriteLock implements ReadWriteLock { + // The Lock ID + private final String lockID; + + // The Curator lock + private final InterProcessReadWriteLock curatorReadWriteLock; + + // The Curator Lock facades for read and write locks + private final CuratorLockFacade readLockFacade; + private final CuratorLockFacade writeLockFacade; + + /** + * Create a Curator lock. + * + * @param curatorFramework the Curator framework to use to create the lock + * @param lockId The unique ID of the lock. + */ + public CuratorReentrantReadWriteLock(final CuratorFramework curatorFramework, final String lockId) { + lockID = lockId; + + // Create the Curator lock + curatorReadWriteLock = new InterProcessReadWriteLock(curatorFramework, lockId); + + // Create the lock facades + readLockFacade = new CuratorLockFacade(curatorReadWriteLock.readLock(), lockId); + writeLockFacade = new CuratorLockFacade(curatorReadWriteLock.writeLock(), lockId); + } + + /** + * Get the lock Id of the lock. + * + * @return the lock ID + */ + public String getLockID() { + return lockID; + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.ReadWriteLock#readLock() + */ + @Override + public Lock readLock() { + return readLockFacade; + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.ReadWriteLock#writeLock() + */ + @Override + public Lock writeLock() { + return writeLockFacade; + } +} diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java new file mode 100644 index 000000000..d867c396a --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Implements locking on context items in APEX context albums using + * Curator centralized locking. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.plugins.context.locking.curator; diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/pom.xml b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/pom.xml new file mode 100644 index 000000000..e82aca52d --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking + 2.0.0-SNAPSHOT + + + plugins-context-locking-hazelcast + ${project.artifactId} + [${project.parent.artifactId}] Plugin for locking using Hazelcast + + + + com.hazelcast + hazelcast + ${version.hazelcast} + + + org.onap.policy.apex-pdp.core + core-infrastructure + ${project.version} + test + + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-hazelcast + ${project.version} + test + + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-infinispan + ${project.version} + test + + + diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java new file mode 100644 index 000000000..73678ad2a --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLock.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.locking.hazelcast; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; + +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.ILock; + +/** + * This class maps a Hazelcast {@link ILock} to a Java {@link ReadWriteLock}. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class HazelcastLock implements ReadWriteLock { + // The Lock ID + private final String lockID; + + // The hazelcast lock + private final ILock readLock; + private final ILock writeLock; + + /** + * Create a Hazelcast lock. + * + * @param hazelcastInstance the hazelcast instance to use to create the lock + * @param lockId The unique ID of the lock. + */ + public HazelcastLock(final HazelcastInstance hazelcastInstance, final String lockId) { + lockID = lockId; + + // Create the Hazelcast read and write locks + readLock = hazelcastInstance.getLock(lockId + "_READ"); + writeLock = hazelcastInstance.getLock(lockId + "_WRITE"); + } + + /** + * Get the lock Id of the lock. + * + * @return the lock ID + */ + public String getLockID() { + return lockID; + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.ReadWriteLock#readLock() + */ + @Override + public Lock readLock() { + return readLock; + } + + /* + * (non-Javadoc) + * + * @see java.util.concurrent.locks.ReadWriteLock#writeLock() + */ + @Override + public Lock writeLock() { + return writeLock; + } +} diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java new file mode 100644 index 000000000..34258bf24 --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/HazelcastLockManager.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.locking.hazelcast; + +import java.util.concurrent.locks.ReadWriteLock; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.context.impl.locking.AbstractLockManager; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +import com.hazelcast.core.Hazelcast; +import com.hazelcast.core.HazelcastInstance; + +/** + * The Class HazelcastLockManager manages Hazelcast locks for locks on items in Apex context albums. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class HazelcastLockManager extends AbstractLockManager { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(HazelcastLockManager.class); + + private HazelcastInstance hazelcastInstance; + + /** + * Constructor, set up a lock manager that uses Hazelcast locking. + * + * @throws ContextException On errors connecting to the Hazelcast cluster + */ + public HazelcastLockManager() throws ContextException { + LOGGER.entry("HazelcastLockManager(): setting up the Hazelcast lock manager . . ."); + + LOGGER.exit("HazelcastLockManager(): Hazelcast lock manager set up"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.context.impl.locking.AbstractLockManager#init(org.onap.policy.apex. + * model. basicmodel.concepts.AxArtifactKey) + */ + @Override + public void init(final AxArtifactKey key) throws ContextException { + LOGGER.entry("init(" + key + ")"); + + super.init(key); + + // Set up the Hazelcast instance for lock handling + hazelcastInstance = Hazelcast.newHazelcastInstance(); + + LOGGER.exit("init(" + key + ")"); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.context.impl.locking.AbstractLockManager#getReentrantReadWriteLock( + * java.lang.String) + */ + @Override + public ReadWriteLock getReentrantReadWriteLock(final String lockId) throws ContextException { + // Check if the framework is active + if (hazelcastInstance != null && hazelcastInstance.getLifecycleService().isRunning()) { + return new HazelcastLock(hazelcastInstance, lockId); + } else { + throw new ContextException("creation of hazelcast lock failed, see error log for details"); + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.context.LockManager#shutdown() + */ + @Override + public void shutdown() { + if (hazelcastInstance == null) { + return; + } + hazelcastInstance.shutdown(); + hazelcastInstance = null; + } +} diff --git a/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java new file mode 100644 index 000000000..8d35556c4 --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/plugins-context-locking-hazelcast/src/main/java/org/onap/policy/apex/plugins/context/locking/hazelcast/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Implements locking on context items in APEX context albums using + * Hazelcast distributed locking. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.plugins.context.locking.hazelcast; diff --git a/plugins/plugins-context/plugins-context-locking/pom.xml b/plugins/plugins-context/plugins-context-locking/pom.xml new file mode 100644 index 000000000..58027218c --- /dev/null +++ b/plugins/plugins-context/plugins-context-locking/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context + plugins-context + 2.0.0-SNAPSHOT + + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking + pom + ${project.artifactId} + + Plugins for 3pps that lock context + + plugins-context-locking-curator + plugins-context-locking-hazelcast + + diff --git a/plugins/plugins-context/plugins-context-persistence/pom.xml b/plugins/plugins-context/plugins-context-persistence/pom.xml new file mode 100644 index 000000000..e791f6155 --- /dev/null +++ b/plugins/plugins-context/plugins-context-persistence/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context + plugins-context + 2.0.0-SNAPSHOT + + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-persistence + plugins-context-persistence + pom + + ${project.artifactId} + Plugins for 3pps that persist context + diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/pom.xml b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/pom.xml new file mode 100644 index 000000000..89152eeb5 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema + plugins-context-schema + 2.0.0-SNAPSHOT + + + plugins-context-schema-avro + ${project.artifactId} + [${project.parent.artifactId}] Plugin for schemas using Avro + + + + org.apache.avro + avro + 1.8.2 + + + org.onap.policy.apex-pdp.model + policy-model + ${project.version} + test + + + diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java new file mode 100644 index 000000000..56d84251f --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroArrayObjectMapper.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData.Array; + +/** + * Object mapper for arrays, uses default behaviour except for a specific default constructor + * implementation. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroArrayObjectMapper extends AvroDirectObjectMapper { + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. + * apache.avro.Schema) + */ + @SuppressWarnings("rawtypes") + @Override + public Object createNewInstance(final Schema avroSchema) { + return new Array(0, avroSchema); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java new file mode 100644 index 000000000..dc281a52b --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroBytesObjectMapper.java @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import java.nio.ByteBuffer; + +import org.apache.avro.Schema; +import org.apache.avro.Schema.Type; +import org.onap.policy.apex.context.ContextRuntimeException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class does string mapping from the Avro BYTES type to a Java byte array. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroBytesObjectMapper implements AvroObjectMapper { + // Get a reference to the logger + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroBytesObjectMapper.class); + + // The user keyAvro type for direct mapping + private AxKey userKey; + private Type avroType; + + // The Apex compatible class + private final Class schemaClass = Byte[].class; + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getJavaClass() + */ + @Override + public Class getJavaClass() { + return schemaClass; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#setAvroType(org.apache. + * avro. Schema.Type) + */ + @Override + public void init(final AxKey intUserKey, final Type initAvroType) { + this.userKey = intUserKey; + this.avroType = initAvroType; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. + * apache. avro.Schema) + */ + @Override + public Object createNewInstance(final Schema avroSchema) { + // By default, we do not create an instance, normal Java object creation for byte arrays is + // sufficient + return null; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getAvroType() + */ + @Override + public Type getAvroType() { + return avroType; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapFromAvro(java.lang. + * Object) + */ + @Override + public Object mapFromAvro(final Object avroObject) { + // The Avro object should be a Utf8 object + if (!(avroObject instanceof ByteBuffer)) { + final String returnString = + userKey.getID() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass() + + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + // Cast the byte buffer object so we get access to its methods + final ByteBuffer byteBufferAvroObject = (ByteBuffer) avroObject; + + // read the byte buffer into a byte array + final byte[] byteArray = new byte[byteBufferAvroObject.remaining()]; + byteBufferAvroObject.get(byteArray); + + return byteArray; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapToAvro(java.lang.Object) + */ + @Override + public Object mapToAvro(final Object object) { + if (object == null) { + final String returnString = userKey.getID() + ": cannot encode a null object of class \"" + + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + // The incoming object should be a byte array + if (!(object instanceof byte[])) { + final String returnString = userKey.getID() + ": object \"" + object + "\" of class \"" + object.getClass() + + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + // Create a ByteBuffer object to serialize the bytes + final ByteBuffer byteBuffer = ByteBuffer.wrap((byte[]) object); + + return byteBuffer; + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java new file mode 100644 index 000000000..acf64c3c9 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroDirectObjectMapper.java @@ -0,0 +1,165 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.avro.Schema; +import org.apache.avro.Schema.Type; +import org.apache.avro.generic.GenericData; +import org.onap.policy.apex.context.ContextRuntimeException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class does direct mapping from Avro classes to Java classes, used for Avro primitive types + * that directly produce Java objects. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroDirectObjectMapper implements AvroObjectMapper { + // Get a reference to the logger + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroDirectObjectMapper.class); + + // Map for Avro primitive types to Java primitive types + private static final Map> AVRO_JAVA_TYPE_MAP = new TreeMap<>(); + + // @formatter:off + // Initialize the mapping + static { + AVRO_JAVA_TYPE_MAP.put(Schema.Type.ARRAY, GenericData.Array.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.BOOLEAN, Boolean.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.DOUBLE, Double.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.ENUM, GenericData.EnumSymbol.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.FIXED, GenericData.Fixed.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.FLOAT, Float.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.INT, Integer.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.LONG, Long.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.MAP, HashMap.class); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.NULL, null); + AVRO_JAVA_TYPE_MAP.put(Schema.Type.RECORD, GenericData.Record.class); + } + // @formatter:on + + // The user keyAvro type for direct mapping + private AxKey userKey; + private Type avroType; + + // The Apex compatible class + private Class schemaClass; + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getJavaClass() + */ + @Override + public Class getJavaClass() { + return schemaClass; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#setAvroType(org.apache. + * avro. Schema.Type) + */ + @Override + public void init(final AxKey initUserKey, final Type initAvroType) { + this.userKey = initUserKey; + this.avroType = initAvroType; + schemaClass = AVRO_JAVA_TYPE_MAP.get(avroType); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. + * apache. avro.Schema) + */ + @Override + public Object createNewInstance(final Schema avroSchema) { + // By default, we do not create an instance, normal Java object creation is sufficient + return null; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getAvroType() + */ + @Override + public Type getAvroType() { + return avroType; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapFromAvro(java.lang. + * Object) + */ + @Override + public Object mapFromAvro(final Object avroObject) { + // Always return null if the schema is a null schema + if (schemaClass == null) { + return null; + } + + // It is legal for the schema class to be null, if the Avro schema has a "null" type then + // the decoded object is always returned as a null + if (!schemaClass.isAssignableFrom(avroObject.getClass())) { + final String returnString = + userKey.getID() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass() + + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + return avroObject; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapToAvro(java.lang.Object) + */ + @Override + public Object mapToAvro(final Object object) { + // Null values are only allowed if the schema class is null + if (object == null) { + if (schemaClass != null) { + final String returnString = userKey.getID() + ": cannot encode a null object of class \"" + + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + } + + // For direct mappings, just work directly with the Java objects + return object; + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java new file mode 100644 index 000000000..ec84450d5 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroEnumObjectMapper.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import java.util.List; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData.EnumSymbol; + +/** + * Object mapper for enums, uses default behaviour except for a specific default constructor + * implementation. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroEnumObjectMapper extends AvroDirectObjectMapper { + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. + * apache.avro.Schema) + */ + @Override + public Object createNewInstance(final Schema avroSchema) { + // Initialize the ENUM to the first ENUM symbol on the list + final List enumSymbols = avroSchema.getEnumSymbols(); + + // Check if any ENUM symbols have been defined + if (enumSymbols == null || enumSymbols.isEmpty()) { + return null; + } + + return new EnumSymbol(avroSchema, enumSymbols.get(0)); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java new file mode 100644 index 000000000..ff8806c86 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroNullableMapper.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import org.apache.avro.Schema; +import org.apache.avro.Schema.Type; + +import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; + +/** + * The Class AvroNullableMapper handles Avro null mappings to Java null values. + * + * @author John Keeney (john.keeney@ericsson.com) + */ +public class AvroNullableMapper extends AvroDirectObjectMapper { + // The wrapped mapper for nullables + private final AvroObjectMapper wrappedMapper; + + /** + * The Constructor. + * + * @param wrappedMapper the wrapped mapper + */ + public AvroNullableMapper(final AvroObjectMapper wrappedMapper) { + this.wrappedMapper = wrappedMapper; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#getJavaClass() + */ + @Override + public Class getJavaClass() { + return wrappedMapper.getJavaClass(); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#init(org.onap.policy. + * apex. model.basicmodel.concepts.AxKey, org.apache.avro.Schema.Type) + */ + @Override + public void init(final AxKey userKey, final Type avroType) { + wrappedMapper.init(userKey, avroType); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#createNewInstance( + * org. apache.avro.Schema) + */ + @Override + public Object createNewInstance(final Schema avroSchema) { + return wrappedMapper.createNewInstance(avroSchema); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#getAvroType() + */ + @Override + public Type getAvroType() { + return Schema.Type.UNION; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#mapFromAvro(java. + * lang. Object) + */ + @Override + public Object mapFromAvro(final Object avroObject) { + if (avroObject == null) { + return null; + } else { + return wrappedMapper.mapFromAvro(avroObject); + } + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroDirectObjectMapper#mapToAvro(java.lang. + * Object) + */ + @Override + public Object mapToAvro(final Object object) { + if (object == null) { + return null; + } else { + throw new ApexRuntimeException("Unions/Nullable is not supported in output event ... Coming soon!"); + } + + } + +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java new file mode 100644 index 000000000..77de5928e --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapper.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import org.apache.avro.Schema; +import org.apache.avro.Schema.Type; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; + +/** + * This interface is used to allow mapping of Avro object to and from Java objects. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public interface AvroObjectMapper { + /** + * Get the Java class produced and consumed by this mapper. + * + * @return the Java class + */ + Class getJavaClass(); + + /** + * Initialize the mapper is working with. + * + * @param userKey the user key + * @param avroType the avro type + */ + void init(AxKey userKey, Type avroType); + + /** + * Create a new instance of the java object the Avro schema maps to. + * + * @param avroSchema the Avro schema to use to create the new instance + * @return a new instance of the object + */ + Object createNewInstance(Schema avroSchema); + + /** + * Set the Avro type the mapper is working with. + * + * @return the avro type + */ + Type getAvroType(); + + /** + * Map the Avro object to an object Apex can handler. + * + * @param avroObject the Avro object to map + * @return the Apex-compatible object + */ + Object mapFromAvro(Object avroObject); + + /** + * Map the Apex object to an Avro object. + * + * @param object the Apex-compatible object + * @return the Avro object + */ + Object mapToAvro(Object object); +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java new file mode 100644 index 000000000..22152a8da --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.avro.Schema; +import org.onap.policy.apex.context.ContextRuntimeException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class maps between Avro types to Java types. This class is thread safe. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroObjectMapperFactory { + // Get a reference to the logger + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroObjectMapperFactory.class); + + // Map for Avro primitive types to Java primitive types + private static final Map> AVRO_OBJECT_MAPPER_MAP = new TreeMap<>(); + + // @formatter:off + // Initialize the mapping + static { + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.ARRAY, AvroArrayObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.BOOLEAN, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.BYTES, AvroBytesObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.DOUBLE, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.ENUM, AvroEnumObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.FIXED, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.FLOAT, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.INT, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.LONG, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.MAP, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.NULL, AvroDirectObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.RECORD, AvroRecordObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.STRING, AvroStringObjectMapper.class); + AVRO_OBJECT_MAPPER_MAP.put(Schema.Type.UNION, null); + } + // @formatter:on + + /** + * Gets the Avro object mapper to use for an artifact with the given key and schema. + * + * @param userKey the key of the artifact + * @param incomingSchema the incoming schema + * @return the avro object mapper + */ + public AvroObjectMapper get(final AxKey userKey, final Schema incomingSchema) { + Schema schema = incomingSchema; + boolean isnullable = false; + if (Schema.Type.UNION.equals(schema.getType())) { + + final List types = schema.getTypes(); + // TODO: properly support UNIONS + // currently only support unions with 2 types, one of which is NULL + final Schema nullschema = Schema.create(Schema.Type.NULL); + if (types.size() != 2 || !types.contains(nullschema)) { + final String resultSting = userKey.getID() + + ": Apex currently only supports UNION schemas with 2 options, one must be NULL"; + LOGGER.warn(resultSting); + throw new ContextRuntimeException(resultSting); + } + isnullable = true; + // get the non-null schema given for the union so it can be wrapped + schema = types.get(0); + if (Schema.Type.NULL.equals(schema.getType())) { + schema = types.get(1); + } + if (Schema.Type.NULL.equals(schema.getType())) { + final String resultSting = userKey.getID() + + ": Apex currently only supports UNION schema2 with 2 options, only one can be NULL, and the other cannot be another UNION"; + LOGGER.warn(resultSting); + throw new ContextRuntimeException(resultSting); + } + } + + final Schema.Type avroType = schema.getType(); + + // Check that there is a definition for the mapper for this type + if (!AVRO_OBJECT_MAPPER_MAP.containsKey(avroType) || AVRO_OBJECT_MAPPER_MAP.get(avroType) == null) { + final String resultSting = + userKey.getID() + ": no Avro object mapper defined for Avro type \"" + avroType + "\""; + LOGGER.warn(resultSting); + throw new ContextRuntimeException(resultSting); + } + + // Create a mapper + AvroObjectMapper avroObjectMapper; + try { + avroObjectMapper = AVRO_OBJECT_MAPPER_MAP.get(avroType).newInstance(); + if (isnullable) { + avroObjectMapper = new AvroNullableMapper(avroObjectMapper); + } + + } catch (final Exception e) { + final String resultSting = userKey.getID() + ": could not create an Avro object mapper of type \"" + + AVRO_OBJECT_MAPPER_MAP.get(avroType) + "\" for Avro type \"" + avroType + "\" : " + e; + LOGGER.warn(resultSting, e); + throw new ContextRuntimeException(resultSting, e); + } + + // Set the type and return + avroObjectMapper.init(userKey, avroType); + + return avroObjectMapper; + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java new file mode 100644 index 000000000..9d24a9a86 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroRecordObjectMapper.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData.Record; + +/** + * Object mapper for records, uses default behaviour except for a specific default constructor + * implementation. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroRecordObjectMapper extends AvroDirectObjectMapper { + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. + * apache. avro.Schema) + */ + @Override + public Object createNewInstance(final Schema avroSchema) { + return new Record(avroSchema); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java new file mode 100644 index 000000000..5fba274ce --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java @@ -0,0 +1,261 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import java.io.ByteArrayOutputStream; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericDatumReader; +import org.apache.avro.generic.GenericDatumWriter; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.io.DatumWriter; +import org.apache.avro.io.DecoderFactory; +import org.apache.avro.io.EncoderFactory; +import org.apache.avro.io.JsonDecoder; +import org.apache.avro.io.JsonEncoder; +import org.onap.policy.apex.context.ContextRuntimeException; +import org.onap.policy.apex.context.impl.schema.AbstractSchemaHelper; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; + +/** + * This class is the implementation of the {@link org.onap.policy.apex.context.SchemaHelper} + * interface for Avro schemas. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroSchemaHelper extends AbstractSchemaHelper { + // Get a reference to the logger + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroSchemaHelper.class); + + // The Avro schema for this context schema + private Schema avroSchema; + + // The mapper that translates between Java and Avro objects + private AvroObjectMapper avroObjectMapper; + + @Override + public void init(final AxKey userKey, final AxContextSchema schema) throws ContextRuntimeException { + super.init(userKey, schema); + + // Configure the Avro schema + try { + avroSchema = new Schema.Parser().parse(schema.getSchema()); + } catch (final Exception e) { + final String resultSting = userKey.getID() + ": avro context schema \"" + schema.getID() + + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema(); + LOGGER.warn(resultSting); + throw new ContextRuntimeException(resultSting); + } + + // Get the object mapper for the schema type to a Java class + avroObjectMapper = new AvroObjectMapperFactory().get(userKey, avroSchema); + + // Get the Java type for this schema, if it is a primitive type then we can do direct + // conversion to JAva + setSchemaClass(avroObjectMapper.getJavaClass()); + } + + /** + * Getter to get the Avro schema. + * + * @return the Avro schema + */ + public Schema getAvroSchema() { + return avroSchema; + } + + @Override + public Object getSchemaObject() { + return avroSchema; + } + + @Override + public Object createNewInstance() { + // Create a new instance using the Avro object mapper + final Object newInstance = avroObjectMapper.createNewInstance(avroSchema); + + // If no new instance is created, use default schema handler behavior + if (newInstance != null) { + return newInstance; + } else { + return super.createNewInstance(); + } + } + + @Override + public Object createNewInstance(final String stringValue) { + return unmarshal(stringValue); + } + + @Override + public Object createNewInstance(final Object incomingObject) { + if (incomingObject instanceof JsonElement) { + final Gson gson = new GsonBuilder().serializeNulls().create(); + final String elementJsonString = gson.toJson((JsonElement) incomingObject); + + return createNewInstance(elementJsonString); + } + else { + final String returnString = getUserKey().getID() + ": the object \"" + incomingObject + + "\" is not an instance of JsonObject"; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + } + + @Override + public Object unmarshal(final Object object) { + // If an object is already in the correct format, just carry on + if (passThroughObject(object)) { + return object; + } + + String objectString = getStringObject(object); + + // Translate illegal characters in incoming JSON keys to legal Avro values + objectString = AvroSchemaKeyTranslationUtilities.translateIllegalKeys(objectString, false); + + // Decode the object + Object decodedObject; + try { + final JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(avroSchema, objectString); + decodedObject = new GenericDatumReader(avroSchema).read(null, jsonDecoder); + } catch (final Exception e) { + final String returnString = getUserKey().getID() + ": object \"" + objectString + + "\" Avro unmarshalling failed: " + e.getMessage(); + LOGGER.warn(returnString, e); + throw new ContextRuntimeException(returnString, e); + } + + // Now map the decoded object into something we can handle + return avroObjectMapper.mapFromAvro(decodedObject); + } + + /** + * Check that the incoming object is a string, the incoming object must be a string containing + * Json + * + * @param object incoming object + * @return object as String + */ + private String getStringObject(final Object object) { + try { + if (isObjectString(object)) { + String objectString = object.toString().trim(); + if (objectString.length() == 0) { + return "\"\""; + } else if (objectString.length() == 1) { + return "\"" + objectString + "\""; + } else { + // All strings must be quoted for decoding + if (objectString.charAt(0) != '"') { + objectString = '"' + objectString; + } + if (objectString.charAt(objectString.length() - 1) != '"') { + objectString += '"'; + } + } + return objectString; + } else { + return (String) object; + } + } catch (final ClassCastException e) { + final String returnString = getUserKey().getID() + ": object \"" + object + "\" of type \"" + + (object != null ? object.getClass().getCanonicalName() : "null") + "\" must be assignable to \"" + + getSchemaClass().getCanonicalName() + + "\" or be a Json string representation of it for Avro unmarshalling"; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + } + + private boolean isObjectString(final Object object) { + return object != null && avroSchema.getType().equals(Schema.Type.STRING); + } + + @Override + public String marshal2String(final Object object) { + // Condition the object for Avro encoding + final Object conditionedObject = avroObjectMapper.mapToAvro(object); + + final String jsonString = getJsonString(object, conditionedObject); + + return AvroSchemaKeyTranslationUtilities.translateIllegalKeys(jsonString, true); + } + + private String getJsonString(final Object object, final Object conditionedObject) { + + try (final ByteArrayOutputStream output = new ByteArrayOutputStream();) { + final DatumWriter writer = new GenericDatumWriter<>(avroSchema); + final JsonEncoder jsonEncoder = EncoderFactory.get().jsonEncoder(avroSchema, output, true); + writer.write(conditionedObject, jsonEncoder); + jsonEncoder.flush(); + return new String(output.toByteArray()); + } catch (final Exception e) { + final String returnString = + getUserKey().getID() + ": object \"" + object + "\" Avro marshalling failed: " + e.getMessage(); + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString, e); + } + } + + @Override + public JsonElement marshal2Object(final Object schemaObject) { + // Get the object as a Json string + final String schemaObjectAsString = marshal2String(schemaObject); + + // Get a Gson instance to convert the Json string to an object created by Json + final Gson gson = new Gson(); + + // Convert the Json string into an object + final Object schemaObjectAsObject = gson.fromJson(schemaObjectAsString, Object.class); + + return gson.toJsonTree(schemaObjectAsObject); + } + + /** + * Check if we can pass this object straight through encoding or decoding, is it an object + * native to the schema. + * + * @param object the object to check + * @return true if it's a straight pass through + */ + private boolean passThroughObject(final Object object) { + if (object == null || getSchemaClass() == null) { + return false; + } + + // All strings must be mapped + if (object instanceof String) { + return false; + } + + // Now, check if the object is native + return getSchemaClass().isAssignableFrom(object.getClass()); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java new file mode 100644 index 000000000..5a8fac404 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperParameters.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import org.onap.policy.apex.context.parameters.SchemaHelperParameters; + +/** + * Schema helper parameter class for the Avro schema helper. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroSchemaHelperParameters extends SchemaHelperParameters { + /** + * The Default Constructor sets the {@link AvroSchemaHelper} as the schema helper class for Avro + * schemas. + */ + public AvroSchemaHelperParameters() { + this.setSchemaHelperPluginClass(AvroSchemaHelper.class.getCanonicalName()); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java new file mode 100644 index 000000000..dc3770a43 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaKeyTranslationUtilities.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import java.util.Map.Entry; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +/** + * This static final class contains utility methods for Avro schemas. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public final class AvroSchemaKeyTranslationUtilities { + // Constants for key replacements + private static final String DOT_STRING = "\\."; + private static final String DOT_STRING_REPLACEMENT = "_DoT_"; + private static final String DASH_STRING = "-"; + private static final String DASH_STRING_REPLACEMENT = "_DasH_"; + + /** + * Default constructor to avoid subclassing. + */ + private AvroSchemaKeyTranslationUtilities() {} + + /** + * Translate characters in JSON keys to values that are legal in Avro. Avro names must start + * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] + * + * @param jsonString The JSON string to translate + * @param revert True if we want to revert the field names to their original values + * @return the translated JSON string + */ + public static String translateIllegalKeys(final String jsonString, final boolean revert) { + if (jsonString == null) { + return jsonString; + } + + // Create a JSON element for the incoming JSON string + final JsonElement jsonElement = + new GsonBuilder().serializeNulls().create().fromJson(jsonString, JsonElement.class); + + final JsonElement translatedJsonElement = translateIllegalKeys(jsonElement, revert); + + return new GsonBuilder().serializeNulls().create().toJson(translatedJsonElement); + } + + /** + * Translate characters in JSON keys to values that are legal in Avro. Avro names must start + * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] + * + * @param jsonElement The JSON element to translate + * @param revert True if we want to revert the field names to their original values + * @return the translated JSON element + */ + public static JsonElement translateIllegalKeys(final JsonElement jsonElement, final boolean revert) { + // We only act on JSON objects and arrays + if (jsonElement.isJsonObject()) { + return translateIllegalKeys(jsonElement.getAsJsonObject(), revert); + } else if (jsonElement.isJsonArray()) { + return translateIllegalKeys(jsonElement.getAsJsonArray(), revert); + } else { + return jsonElement; + } + } + + /** + * Translate characters in JSON keys to values that are legal in Avro. Avro names must start + * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] + * + * @param jsonObject The JSON object to translate + * @param revert True if we want to revert the field names to their original values + * @return the translated JSON element + */ + public static JsonElement translateIllegalKeys(final JsonObject jsonObject, final boolean revert) { + final JsonObject newJsonObject = new JsonObject(); + + for (final Entry jsonObjectEntry : jsonObject.entrySet()) { + newJsonObject.add(translateIllegalKey(jsonObjectEntry.getKey(), revert), + translateIllegalKeys(jsonObjectEntry.getValue(), revert)); + } + + return newJsonObject; + } + + /** + * Translate characters in JSON keys to values that are legal in Avro. Avro names must start + * with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] + * + * @param jsonArray The JSON array to translate + * @param revert True if we want to revert the field names to their original values + * @return the translated JSON element + */ + public static JsonElement translateIllegalKeys(final JsonArray jsonArray, final boolean revert) { + final JsonArray newJsonArray = new JsonArray(); + + for (int i = 0; i < jsonArray.size(); i++) { + newJsonArray.add(translateIllegalKeys(jsonArray.get(i), revert)); + } + + return newJsonArray; + } + + /** + * Translate characters in a single JSON key to values that are legal in Avro. Avro names must + * start with [A-Za-z_] and subsequently contain only [A-Za-z0-9_] + * + * @param key The key to translate + * @param revert True if we want to revert the field names to their original values + * @return the translated key + */ + private static String translateIllegalKey(final String key, final boolean revert) { + if (revert) { + return key.replaceAll(DOT_STRING_REPLACEMENT, DOT_STRING).replaceAll(DASH_STRING_REPLACEMENT, DASH_STRING); + } else { + return key.replaceAll(DOT_STRING, DOT_STRING_REPLACEMENT).replaceAll(DASH_STRING, DASH_STRING_REPLACEMENT); + } + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java new file mode 100644 index 000000000..cb3625f31 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroStringObjectMapper.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import org.apache.avro.Schema; +import org.apache.avro.Schema.Type; +import org.apache.avro.util.Utf8; +import org.onap.policy.apex.context.ContextRuntimeException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class does string mapping from the Avro Utf8 class to the Java String class. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class AvroStringObjectMapper implements AvroObjectMapper { + // Get a reference to the logger + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroStringObjectMapper.class); + + // The user keyAvro type for direct mapping + private AxKey userKey; + private Type avroType; + + // The Apex compatible class + private final Class schemaClass = String.class; + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getJavaClass() + */ + @Override + public Class getJavaClass() { + return schemaClass; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#setAvroType(org.apache. + * avro. Schema.Type) + */ + @Override + public void init(final AxKey initUserKey, final Type initAvroType) { + this.userKey = initUserKey; + this.avroType = initAvroType; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#createNewinstance(org. + * apache. avro.Schema) + */ + @Override + public Object createNewInstance(final Schema avroSchema) { + // By default, we do not create an instance, normal Java object creation for strings is + // sufficient + return null; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#getAvroType() + */ + @Override + public Type getAvroType() { + return avroType; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapFromAvro(java.lang. + * Object) + */ + @Override + public Object mapFromAvro(final Object avroObject) { + // The Avro object should be a Utf8 object + if (!(avroObject instanceof Utf8)) { + final String returnString = + userKey.getID() + ": object \"" + avroObject + "\" of class \"" + avroObject.getClass() + + "\" cannot be decoded to an object of class \"" + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + return avroObject.toString(); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.plugins.context.schema.avro.AvroObjectMapper#mapToAvro(java.lang.Object) + */ + @Override + public Object mapToAvro(final Object object) { + if (object == null) { + final String returnString = userKey.getID() + ": cannot encode a null object of class \"" + + schemaClass.getCanonicalName() + "\""; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } + + return object; + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java new file mode 100644 index 000000000..93f4943d5 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Implements Avro schem handling for use in event fields and + * context albums in APEX. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.plugins.context.schema.avro; diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java new file mode 100644 index 000000000..65eef39c2 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaAAI.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.avro.generic.GenericData.Array; +import org.apache.avro.generic.GenericRecord; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaAAI { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String aaiInventoryResponseSchema; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + aaiInventoryResponseSchema = + TextFileUtils.getTextFileAsString("src/test/resources/avsc/AAIInventoryResponseItemType.avsc"); + } + + @Test + public void testAAIResponsePolicy() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", aaiInventoryResponseSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final Array newArrayEmpty = (Array) schemaHelper.createNewInstance(); + assertEquals(0, newArrayEmpty.size()); + + final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/AAIResponse4Policy.json"); + final Array newArrayFull = (Array) schemaHelper.createNewInstance(inString); + final String vnfName = ((GenericRecord) ((GenericRecord) newArrayFull.get(0)).get("generic_DasH_vnf")) + .get("vnf_DasH_name").toString(); + assertEquals("ZRDM2MMEX39", vnfName); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java new file mode 100644 index 000000000..21fab66d9 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaArray.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.avro.generic.GenericData.Array; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaArray { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String longArraySchema; + private String addressArraySchema; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + longArraySchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/ArrayExampleLong.avsc"); + addressArraySchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/ArrayExampleAddress.avsc"); + } + + @Test + public void testArrayInit() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", addressArraySchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final Array newArrayEmpty = (Array) schemaHelper.createNewInstance(); + assertEquals(0, newArrayEmpty.size()); + + final String inString = + TextFileUtils.getTextFileAsString("src/test/resources/data/ArrayExampleAddressFull.json"); + final Array newArrayFull = (Array) schemaHelper.createNewInstance(inString); + assertEquals("{\"streetaddress\": \"1600 Pennsylvania Avenue\", \"city\": \"Washington DC\"}", + newArrayFull.get(0).toString()); + } + + @Test + public void testLongArrayUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", longArraySchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleLongNull.json"); + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleLongFull.json"); + } + + @Test + public void testAddressArrayUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", addressArraySchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleAddressNull.json"); + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/ArrayExampleAddressFull.json"); + } + + private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { + final String inString = TextFileUtils.getTextFileAsString(fileName); + final Array schemaObject = (Array) schemaHelper.unmarshal(inString); + final String outString = schemaHelper.marshal2String(schemaObject); + assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java new file mode 100644 index 000000000..ae19cd31a --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaEnum.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.apache.avro.generic.GenericData.EnumSymbol; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaEnum { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String enumSchema; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + enumSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/EnumSchema.avsc"); + } + + @Test + public void testEnumInit() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", enumSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final EnumSymbol newEnumEmpty = (EnumSymbol) schemaHelper.createNewInstance(); + assertEquals("SPADES", newEnumEmpty.toString()); + + final EnumSymbol newEnumFull = (EnumSymbol) schemaHelper.createNewInstance("\"HEARTS\""); + assertEquals("HEARTS", newEnumFull.toString()); + } + + @Test + public void testEnumUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", enumSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleHearts.json"); + + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", + e.getMessage()); + } + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", + e.getMessage()); + } + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad0.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed: Unknown symbol in enum TWEED", + e.getMessage()); + } + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad1.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed: Unknown symbol in enum Hearts", + e.getMessage()); + } + } + + private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { + final String inString = TextFileUtils.getTextFileAsString(fileName); + final EnumSymbol decodedObject = (EnumSymbol) schemaHelper.unmarshal(inString); + final String outString = schemaHelper.marshal2String(decodedObject); + assertEquals(inString.replaceAll("[\\r?\\n]+", " "), outString.replaceAll("[\\r?\\n]+", " ")); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java new file mode 100644 index 000000000..41f622115 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaFixed.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.apache.avro.generic.GenericData.Fixed; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaFixed { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String fixedSchema; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + fixedSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/FixedSchema.avsc"); + } + + @Test + public void testFixedInit() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", fixedSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + try { + schemaHelper.createNewInstance(); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"org.apache.avro.generic.GenericData.Fixed\" using the default constructor \"Fixed()\"", + e.getMessage()); + } + + final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/FixedExampleGood.json"); + final Fixed newFixedFull = (Fixed) schemaHelper.createNewInstance(inString); + assertTrue(newFixedFull.toString().startsWith("[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65")); + assertTrue(newFixedFull.toString().endsWith("53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70]")); + } + + @Test + public void testFixedUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "Avro", fixedSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleGood.json"); + + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", + e.getMessage()); + } + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL", + e.getMessage()); + } + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: object \"\"BADBAD\"\" Avro unmarshalling failed: Expected fixed length 64, but got6", + e.getMessage()); + } + try { + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json"); + fail("This test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: object \"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" Avro unmarshalling failed: Expected fixed length 64, but got65", + e.getMessage()); + } + } + + private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { + final String inString = TextFileUtils.getTextFileAsString(fileName); + final Fixed decodedObject = (Fixed) schemaHelper.unmarshal(inString); + final String outString = schemaHelper.marshal2String(decodedObject); + assertEquals(inString.replaceAll("[\\r?\\n]+", " "), outString.replaceAll("[\\r?\\n]+", " ")); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java new file mode 100644 index 000000000..1e1a0bee0 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperBadSchemas.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaHelperBadSchemas { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + + @Before + public void initTest() { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + } + + @Test + public void badSchemaTest() { + final AxContextSchema avroBadSchema0 = new AxContextSchema(new AxArtifactKey("AvroBad0", "0.0.1"), "Avro", "}"); + schemas.getSchemasMap().put(avroBadSchema0.getKey(), avroBadSchema0); + + try { + new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema0.getKey()); + fail("This test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad0:0.0.1\" schema is invalid")); + } + + final AxContextSchema avroBadSchema1 = new AxContextSchema(new AxArtifactKey("AvroBad1", "0.0.1"), "Avro", ""); + schemas.getSchemasMap().put(avroBadSchema1.getKey(), avroBadSchema1); + + try { + new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema1.getKey()); + fail("This test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad1:0.0.1\" schema is invalid")); + } + + final AxContextSchema avroBadSchema2 = + new AxContextSchema(new AxArtifactKey("AvroBad2", "0.0.1"), "Avro", "{}"); + schemas.getSchemasMap().put(avroBadSchema2.getKey(), avroBadSchema2); + + try { + new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema2.getKey()); + fail("This test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad2:0.0.1\" schema is invalid")); + } + + final AxContextSchema avroBadSchema3 = + new AxContextSchema(new AxArtifactKey("AvroBad3", "0.0.1"), "Avro", "{zooby}"); + schemas.getSchemasMap().put(avroBadSchema3.getKey(), avroBadSchema3); + + try { + new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema3.getKey()); + fail("This test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad3:0.0.1\" schema is invalid")); + } + + final AxContextSchema avroBadSchema4 = + new AxContextSchema(new AxArtifactKey("AvroBad4", "0.0.1"), "Avro", "{\"zooby\"}"); + schemas.getSchemasMap().put(avroBadSchema4.getKey(), avroBadSchema4); + + try { + new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema4.getKey()); + fail("This test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad4:0.0.1\" schema is invalid")); + } + + final AxContextSchema avroBadSchema5 = + new AxContextSchema(new AxArtifactKey("AvroBad5", "0.0.1"), "Avro", "{\"type\": \"zooby\"}"); + schemas.getSchemasMap().put(avroBadSchema5.getKey(), avroBadSchema5); + + try { + new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema5.getKey()); + fail("This test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad5:0.0.1\" schema is invalid")); + } + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java new file mode 100644 index 000000000..a710a2376 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperMarshal.java @@ -0,0 +1,277 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaHelperMarshal { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + + @Before + public void initTest() { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + } + + @Test + public void testNullMarshal() { + final AxContextSchema avroNullSchema = + new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "Avro", "{\"type\": \"null\"}"); + + schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema); + final SchemaHelper schemaHelper0 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey()); + + assertEquals("null", schemaHelper0.marshal2String(null)); + assertEquals("null", schemaHelper0.marshal2String(123)); + assertEquals("null", schemaHelper0.marshal2String("Everything is marshalled to Null, no matter what it is")); + } + + @Test + public void testBooleanMarshal() { + final AxContextSchema avroBooleanSchema = + new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "Avro", "{\"type\": \"boolean\"}"); + + schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema); + final SchemaHelper schemaHelper1 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey()); + + assertEquals("true", schemaHelper1.marshal2String(true)); + assertEquals("false", schemaHelper1.marshal2String(false)); + try { + schemaHelper1.marshal2String(0); + fail("Test should throw an exception here"); + } catch (final Exception e) { + e.printStackTrace(); + assertEquals( + "AvroTest:0.0.1: object \"0\" Avro marshalling failed: java.lang.Integer cannot be cast to java.lang.Boolean", + e.getMessage()); + } + try { + schemaHelper1.marshal2String("0"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + e.printStackTrace(); + assertEquals( + "AvroTest:0.0.1: object \"0\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Boolean", + e.getMessage()); + } + } + + @Test + public void testIntMarshal() { + final AxContextSchema avroIntSchema = + new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "Avro", "{\"type\": \"int\"}"); + + schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema); + final SchemaHelper schemaHelper2 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey()); + + assertEquals("0", schemaHelper2.marshal2String(0)); + assertEquals("1", schemaHelper2.marshal2String(1)); + assertEquals("-1", schemaHelper2.marshal2String(-1)); + assertEquals("1", schemaHelper2.marshal2String(1.23)); + assertEquals("-1", schemaHelper2.marshal2String(-1.23)); + assertEquals("2147483647", schemaHelper2.marshal2String(2147483647)); + assertEquals("-2147483648", schemaHelper2.marshal2String(-2147483648)); + try { + schemaHelper2.marshal2String("Hello"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Number")); + } + try { + schemaHelper2.marshal2String(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\"")); + } + } + + @Test + public void testLongMarshal() { + final AxContextSchema avroLongSchema = + new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "Avro", "{\"type\": \"long\"}"); + + schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema); + final SchemaHelper schemaHelper3 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey()); + + assertEquals("0", schemaHelper3.marshal2String(0L)); + assertEquals("1", schemaHelper3.marshal2String(1L)); + assertEquals("-1", schemaHelper3.marshal2String(-1L)); + assertEquals("9223372036854775807", schemaHelper3.marshal2String(9223372036854775807L)); + assertEquals("-9223372036854775808", schemaHelper3.marshal2String(-9223372036854775808L)); + try { + schemaHelper3.marshal2String("Hello"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Long")); + } + try { + schemaHelper3.marshal2String(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\"")); + } + } + + @Test + public void testFloatMarshal() { + final AxContextSchema avroFloatSchema = + new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "Avro", "{\"type\": \"float\"}"); + + schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema); + final SchemaHelper schemaHelper4 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey()); + + assertEquals("0.0", schemaHelper4.marshal2String(0F)); + assertEquals("1.0", schemaHelper4.marshal2String(1F)); + assertEquals("-1.0", schemaHelper4.marshal2String(-1F)); + assertEquals("1.23", schemaHelper4.marshal2String(1.23F)); + assertEquals("-1.23", schemaHelper4.marshal2String(-1.23F)); + assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F)); + assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F)); + assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F)); + assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F)); + try { + schemaHelper4.marshal2String("Hello"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Float")); + } + try { + schemaHelper4.marshal2String(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\"")); + } + } + + + @Test + public void testDoubleMarshal() { + final AxContextSchema avroDoubleSchema = + new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "Avro", "{\"type\": \"double\"}"); + + schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema); + final SchemaHelper schemaHelper5 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey()); + + assertEquals("0.0", schemaHelper5.marshal2String(0D)); + assertEquals("1.0", schemaHelper5.marshal2String(1D)); + assertEquals("-1.0", schemaHelper5.marshal2String(-1D)); + assertEquals("1.23", schemaHelper5.marshal2String(1.23)); + assertEquals("-1.23", schemaHelper5.marshal2String(-1.23)); + assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18)); + assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18)); + assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18)); + assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18)); + try { + schemaHelper5.marshal2String("Hello"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: java.lang.String cannot be cast to java.lang.Double")); + } + try { + schemaHelper5.marshal2String(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\"")); + } + } + + @Test + public void testStringMarshal() { + final AxContextSchema avroStringSchema = + new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"string\"}"); + + schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema); + final SchemaHelper schemaHelper7 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey()); + + assertEquals("\"0\"", schemaHelper7.marshal2String("0")); + assertEquals("\"1\"", schemaHelper7.marshal2String("1")); + assertEquals("\"-1\"", schemaHelper7.marshal2String("-1")); + assertEquals("\"1.23\"", schemaHelper7.marshal2String("1.23")); + assertEquals("\"-1.23\"", schemaHelper7.marshal2String("-1.23")); + assertEquals("\"9223372036854775807\"", schemaHelper7.marshal2String("9223372036854775807")); + assertEquals("\"-9223372036854775808\"", schemaHelper7.marshal2String("-9223372036854775808")); + assertEquals("\"9223372036854775808\"", schemaHelper7.marshal2String("9223372036854775808")); + assertEquals("\"-9223372036854775809\"", schemaHelper7.marshal2String("-9223372036854775809")); + assertEquals("\"Hello\"", schemaHelper7.marshal2String("Hello")); + try { + schemaHelper7.marshal2String(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\"")); + } + } + + @Test + public void testBytesMarshal() { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"bytes\"}"); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final byte[] helloBytes = {104, 101, 108, 108, 111}; + final String helloOut = schemaHelper.marshal2String(helloBytes); + assertEquals("\"hello\"", helloOut); + + try { + schemaHelper.marshal2String(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage() + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Byte[]\"")); + } + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java new file mode 100644 index 000000000..725ebb221 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaHelperUnmarshal.java @@ -0,0 +1,371 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.avro.util.Utf8; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaHelperUnmarshal { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + + @Before + public void initTest() { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + } + + // @Test + public void testNullUnmarshal() { + final AxContextSchema avroNullSchema = + new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "Avro", "{\"type\": \"null\"}"); + + schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema); + final SchemaHelper schemaHelper0 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey()); + + try { + schemaHelper0.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("AvroTest:0.0.1: could not create an instance, schema class for the schema is null", + e.getMessage()); + } + + assertEquals(null, schemaHelper0.unmarshal("null")); + + try { + schemaHelper0.unmarshal("123"); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: Expected null. Got VALUE_NUMBER_INT", + e.getMessage()); + } + } + + // @Test + public void testBooleanUnmarshal() { + final AxContextSchema avroBooleanSchema = + new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "Avro", "{\"type\": \"boolean\"}"); + + schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema); + final SchemaHelper schemaHelper1 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey()); + + try { + schemaHelper1.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" using the default constructor \"Boolean()\"", + e.getMessage()); + } + assertEquals(true, schemaHelper1.createNewInstance("true")); + + assertEquals(true, schemaHelper1.unmarshal("true")); + assertEquals(false, schemaHelper1.unmarshal("false")); + try { + schemaHelper1.unmarshal(0); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: object \"0\" Avro unmarshalling failed: Expected boolean. Got VALUE_NUMBER_INT", + e.getMessage()); + } + } + + // @Test + public void testIntUnmarshal() { + final AxContextSchema avroIntSchema = + new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "Avro", "{\"type\": \"int\"}"); + + schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema); + final SchemaHelper schemaHelper2 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey()); + + try { + schemaHelper2.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" using the default constructor \"Integer()\"", + e.getMessage()); + } + assertEquals(123, schemaHelper2.createNewInstance("123")); + + assertEquals(0, schemaHelper2.unmarshal("0")); + assertEquals(1, schemaHelper2.unmarshal("1")); + assertEquals(-1, schemaHelper2.unmarshal("-1")); + assertEquals(1, schemaHelper2.unmarshal("1.23")); + assertEquals(-1, schemaHelper2.unmarshal("-1.23")); + assertEquals(2147483647, schemaHelper2.unmarshal("2147483647")); + assertEquals(-2147483648, schemaHelper2.unmarshal("-2147483648")); + try { + schemaHelper2.unmarshal("2147483648"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: Numeric value (2147483648) out of range of int")); + } + try { + schemaHelper2.unmarshal("-2147483649"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: Numeric value (-2147483649) out of range of int")); + } + try { + schemaHelper2.unmarshal(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); + } + } + + // @Test + public void testLongUnmarshal() { + final AxContextSchema avroLongSchema = + new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "Avro", "{\"type\": \"long\"}"); + + schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema); + final SchemaHelper schemaHelper3 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey()); + + try { + schemaHelper3.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" using the default constructor \"Long()\"", + e.getMessage()); + } + assertEquals(123456789L, schemaHelper3.createNewInstance("123456789")); + + assertEquals(0L, schemaHelper3.unmarshal("0")); + assertEquals(1L, schemaHelper3.unmarshal("1")); + assertEquals(-1L, schemaHelper3.unmarshal("-1")); + assertEquals(1L, schemaHelper3.unmarshal("1.23")); + assertEquals(-1L, schemaHelper3.unmarshal("-1.23")); + assertEquals(9223372036854775807L, schemaHelper3.unmarshal("9223372036854775807")); + assertEquals(-9223372036854775808L, schemaHelper3.unmarshal("-9223372036854775808")); + try { + schemaHelper3.unmarshal("9223372036854775808"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: Numeric value (9223372036854775808) out of range of long")); + } + try { + schemaHelper3.unmarshal("-9223372036854775809"); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith( + "AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: Numeric value (-9223372036854775809) out of range of long")); + } + try { + schemaHelper3.unmarshal("\"Hello\""); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected long. Got VALUE_STRING")); + } + try { + schemaHelper3.unmarshal(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); + } + } + + // @Test + public void testFloatUnmarshal() { + final AxContextSchema avroFloatSchema = + new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "Avro", "{\"type\": \"float\"}"); + + schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema); + final SchemaHelper schemaHelper4 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey()); + + try { + schemaHelper4.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" using the default constructor \"Float()\"", + e.getMessage()); + } + assertEquals(1.2345F, schemaHelper4.createNewInstance("1.2345")); + + assertEquals(0.0F, schemaHelper4.unmarshal("0")); + assertEquals(1.0F, schemaHelper4.unmarshal("1")); + assertEquals(-1.0F, schemaHelper4.unmarshal("-1")); + assertEquals(1.23F, schemaHelper4.unmarshal("1.23")); + assertEquals(-1.23F, schemaHelper4.unmarshal("-1.23")); + assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775807")); + assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775808")); + assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775808")); + assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775809")); + try { + schemaHelper4.unmarshal("\"Hello\""); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected float. Got VALUE_STRING")); + } + try { + schemaHelper4.unmarshal(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); + } + } + + // @Test + public void testDoubleUnmarshal() { + final AxContextSchema avroDoubleSchema = + new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "Avro", "{\"type\": \"double\"}"); + + schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema); + final SchemaHelper schemaHelper5 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey()); + + try { + schemaHelper5.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" using the default constructor \"Double()\"", + e.getMessage()); + } + assertEquals(1.2345E06, schemaHelper5.createNewInstance("1.2345E06")); + + assertEquals(0.0, schemaHelper5.unmarshal("0")); + assertEquals(1.0, schemaHelper5.unmarshal("1")); + assertEquals(-1.0, schemaHelper5.unmarshal("-1")); + assertEquals(1.23, schemaHelper5.unmarshal("1.23")); + assertEquals(-1.23, schemaHelper5.unmarshal("-1.23")); + assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775807")); + assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775808")); + assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775808")); + assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775809")); + try { + schemaHelper5.unmarshal("\"Hello\""); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: Expected double. Got VALUE_STRING")); + } + try { + schemaHelper5.unmarshal(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); + } + } + + @Test + public void testStringUnmarshal() { + final AxContextSchema avroStringSchema = + new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"string\"}"); + + schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema); + final SchemaHelper schemaHelper7 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey()); + + assertEquals("", schemaHelper7.createNewInstance("")); + assertEquals("1.2345E06", schemaHelper7.createNewInstance("1.2345E06")); + + assertEquals("0", schemaHelper7.unmarshal("0")); + assertEquals("1", schemaHelper7.unmarshal("1")); + assertEquals("-1", schemaHelper7.unmarshal("-1")); + assertEquals("1.23", schemaHelper7.unmarshal("1.23")); + assertEquals("-1.23", schemaHelper7.unmarshal("-1.23")); + assertEquals("9223372036854775807", schemaHelper7.unmarshal("9223372036854775807")); + assertEquals("-9223372036854775808", schemaHelper7.unmarshal("-9223372036854775808")); + assertEquals("9223372036854775808", schemaHelper7.unmarshal("9223372036854775808")); + assertEquals("-9223372036854775809", schemaHelper7.unmarshal("-9223372036854775809")); + assertEquals("Hello", schemaHelper7.unmarshal("Hello")); + assertEquals("Hello", schemaHelper7.unmarshal(new Utf8("Hello"))); + try { + schemaHelper7.unmarshal(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); + } + } + + @Test + public void testBytesUnmarshal() { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "Avro", "{\"type\": \"bytes\"}"); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + try { + schemaHelper.createNewInstance(); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals( + "AvroTest:0.0.1: could not create an instance of class \"java.lang.Byte[]\" using the default constructor \"Byte[]()\"", + e.getMessage()); + } + final byte[] newBytes = (byte[]) schemaHelper.createNewInstance("\"hello\""); + assertEquals(5, newBytes.length); + assertEquals(104, newBytes[0]); + assertEquals(101, newBytes[1]); + assertEquals(108, newBytes[2]); + assertEquals(108, newBytes[3]); + assertEquals(111, newBytes[4]); + + try { + schemaHelper.unmarshal(null); + fail("Test should throw an exception here"); + } catch (final Exception e) { + assertTrue(e.getMessage().equals( + "AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: String to read from cannot be null!")); + } + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java new file mode 100644 index 000000000..33ca512b9 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaMap.java @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +import org.apache.avro.util.Utf8; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaMap { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String longMapSchema; + private String addressMapSchema; + private String addressMapSchemaInvalidFields; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + longMapSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleLong.avsc"); + addressMapSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddress.avsc"); + addressMapSchemaInvalidFields = + TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddressInvalidFields.avsc"); + } + + @Test + public void testMapInit() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", addressMapSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final HashMap newMapEmpty = (HashMap) schemaHelper.createNewInstance(); + assertEquals(0, newMapEmpty.size()); + + final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/MapExampleAddressFull.json"); + final HashMap newMapFull = (HashMap) schemaHelper.createNewInstance(inString); + + assertEquals("{\"streetaddress\": \"221 B Baker St.\", \"city\": \"London\"}", + newMapFull.get(new Utf8("address2")).toString()); + } + + @Test + public void testLongMapUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "Avro", longMapSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleLongNull.json"); + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleLongFull.json"); + } + + @Test + public void testAddressMapUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "Avro", addressMapSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressNull.json"); + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressFull.json"); + } + + @Test + public void testAddressMapUnmarshalMarshalInvalidFields() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "Avro", addressMapSchemaInvalidFields); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/MapExampleAddressInvalidFields.json"); + } + + private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { + final String originalInString = TextFileUtils.getTextFileAsString(fileName); + final HashMap firstDecodedMap = (HashMap) schemaHelper.unmarshal(originalInString); + + final String outString = schemaHelper.marshal2String(firstDecodedMap); + + final File tempOutFile = File.createTempFile("ApexAvro", ".json"); + TextFileUtils.putStringAsFile(outString, tempOutFile); + + final String decodeEncodeInString = TextFileUtils.getTextFileAsString(fileName); + tempOutFile.delete(); + + final HashMap secondDecodedMap = (HashMap) schemaHelper.unmarshal(decodeEncodeInString); + + // Now check that our doubly encoded map equals the first decoded map, Java map equals + // checks values and keys + assertEquals(firstDecodedMap, secondDecodedMap); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java new file mode 100644 index 000000000..e14236064 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaRecord.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.avro.generic.GenericRecord; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaRecord { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String recordSchema; + private String recordSchemaVPN; + private String recordSchemaVPNReuse; + private String recordSchemaInvalidFields; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + recordSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExample.avsc"); + recordSchemaVPN = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPN.avsc"); + recordSchemaVPNReuse = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPNReuse.avsc"); + recordSchemaInvalidFields = + TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleInvalidFields.avsc"); + } + + @Test + public void testRecordInit() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final GenericRecord newRecordEmpty = (GenericRecord) schemaHelper.createNewInstance(); + assertEquals(null, newRecordEmpty.get("passwordHash")); + + final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/RecordExampleFull.json"); + final GenericRecord newRecordFull = (GenericRecord) schemaHelper.createNewInstance(inString); + assertEquals("gobbledygook", newRecordFull.get("passwordHash").toString()); + } + + @Test + public void testRecordUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleNull.json"); + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleFull.json"); + } + + @Test + public void testRecordUnmarshalMarshalInvalid() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchemaInvalidFields); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleInvalidFields.json"); + } + + @Test + public void testVPNRecordUnmarshalMarshal() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchemaVPN); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/RecordExampleVPNFull.json"); + } + + @Test + public void testVPNRecordReuse() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", recordSchemaVPNReuse); + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + } + + private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { + final String inString = TextFileUtils.getTextFileAsString(fileName); + final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString); + final String outString = schemaHelper.marshal2String(decodedObject); + assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java new file mode 100644 index 000000000..100b51d44 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestAvroSchemaUnion.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.avro.generic.GenericRecord; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + * @version + */ +public class TestAvroSchemaUnion { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String uinionSchema; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + uinionSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/UnionExample.avsc"); + } + + @Ignore + @Test + public void testUnionAllFields() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", uinionSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleAllFields.json"); + final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString); + + assertEquals("Ben", user.get("name").toString()); + assertEquals(7, user.get("favourite_number")); + assertEquals("red", user.get("favourite_colour").toString()); + } + + @Ignore + @Test + public void testUnionOptionalField() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", uinionSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final String inString = + TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleOptionalField.json"); + final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString); + + assertEquals("Ben", user.get("name").toString()); + assertEquals(7, user.get("favourite_number")); + assertEquals("red", user.get("favourite_colour").toString()); + } + + @Ignore + @Test + public void testUnionNullField() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", uinionSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/UnionExampleNullField.json"); + final GenericRecord user = (GenericRecord) schemaHelper.createNewInstance(inString); + + assertEquals("Ben", user.get("name").toString()); + assertEquals(7, user.get("favourite_number")); + assertEquals("red", user.get("favourite_colour").toString()); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java new file mode 100644 index 000000000..026125af9 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/TestHealthCheckSchema.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.context.schema.avro; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericData.Record; +import org.apache.avro.generic.GenericRecord; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.SchemaHelper; +import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestHealthCheckSchema { + private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1"); + private AxContextSchemas schemas; + private String healthCheckSchema; + + @Before + public void initTest() throws IOException { + schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1")); + ModelService.registerModel(AxContextSchemas.class, schemas); + + new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + healthCheckSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/HealthCheckBodyType.avsc"); + } + + + @Test + public void testHealthCheck() throws IOException { + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "Avro", healthCheckSchema); + + schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); + final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); + + testUnmarshalMarshal(schemaHelper, "src/test/resources/data/HealthCheckEvent.json"); + + final GenericRecord healthCheckRecord = (Record) schemaHelper.createNewInstance(); + final Schema healthCheckRecordSchema = healthCheckRecord.getSchema(); + + final GenericRecord inputRecord = new GenericData.Record(healthCheckRecordSchema.getField("input").schema()); + final Schema inputRecordRecordSchema = inputRecord.getSchema(); + + final GenericRecord actionIndentifiersRecord = + new GenericData.Record(inputRecordRecordSchema.getField("action_DasH_identifiers").schema()); + + final GenericRecord commonHeaderRecord = + new GenericData.Record(inputRecordRecordSchema.getField("common_DasH_header").schema()); + final Schema commonHeaderRecordSchema = commonHeaderRecord.getSchema(); + + final GenericRecord commonHeaderFlagsRecord = + new GenericData.Record(commonHeaderRecordSchema.getField("flags").schema()); + + healthCheckRecord.put("input", inputRecord); + inputRecord.put("action_DasH_identifiers", actionIndentifiersRecord); + inputRecord.put("common_DasH_header", commonHeaderRecord); + commonHeaderRecord.put("flags", commonHeaderFlagsRecord); + + inputRecord.put("action", "HealthCheck"); + inputRecord.put("payload", + "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\",\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}"); + + actionIndentifiersRecord.put("vnf_DasH_id", "49414df5-3482-4fd8-9952-c463dff2770b"); + + commonHeaderRecord.put("request_DasH_id", "afr-request3"); + commonHeaderRecord.put("originator_DasH_id", "AFR"); + commonHeaderRecord.put("api_DasH_ver", "2.15"); + commonHeaderRecord.put("sub_DasH_request_DasH_id", "AFR-subrequest"); + commonHeaderRecord.put("timestamp", "2017-11-06T15:15:18.97Z"); + + commonHeaderFlagsRecord.put("ttl", "10000"); + commonHeaderFlagsRecord.put("force", "TRUE"); + commonHeaderFlagsRecord.put("mode", "EXCLUSIVE"); + + final String eventString = TextFileUtils.getTextFileAsString("src/test/resources/data/HealthCheckEvent.json"); + final String outString = schemaHelper.marshal2String(healthCheckRecord); + assertEquals(eventString.toString().replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); + } + + private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException { + final String inString = TextFileUtils.getTextFileAsString(fileName); + final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString); + final String outString = schemaHelper.marshal2String(decodedObject); + assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", "")); + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc new file mode 100644 index 000000000..d4ae592a1 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/AAIInventoryResponseItemType.avsc @@ -0,0 +1,70 @@ +{ + "type": "array", + "items": { + "type": "record", + "name": "AAIInventoryResponseItem_Type", + "fields": [ + { + "name": "model_DasH_name", + "type": "string" + }, + { + "name": "extra_DasH_properties", + "type": { + "type": "record", + "name": "AAIInventoryResponseItemExtraProperties_Type", + "fields": [] + } + }, + { + "name": "generic_DasH_vnf", + "type": { + "type": "record", + "name": "AAIInventoryResponseItemGenericVNF_Type", + "fields": [ + { + "name": "vnf_DasH_id", + "type": "string" + }, + { + "name": "vnf_DasH_name", + "type": "string" + }, + { + "name": "vnf_DasH_type", + "type": "string" + }, + { + "name": "service_DasH_id", + "type": "string" + }, + { + "name": "orchestration_DasH_status", + "type": "string" + }, + { + "name": "in_DasH_maint", + "type": "boolean" + }, + { + "name": "is_DasH_closed_DasH_loop_DasH_disabled", + "type": "boolean" + }, + { + "name": "resource_DasH_version", + "type": "string" + }, + { + "name": "model_DasH_invariant_DasH_id", + "type": "string" + }, + { + "name": "model_DasH_version_DasH_id", + "type": "string" + } + ] + } + } + ] + } +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc new file mode 100644 index 000000000..0967d6210 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleAddress.avsc @@ -0,0 +1,10 @@ +{ + "type": "array", "items": { + "type" : "record", + "name" : "AddressUSRecord", + "fields" : [ + {"name": "streetaddress", "type": "string"}, + {"name": "city", "type": "string"} + ] + } +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc new file mode 100644 index 000000000..91f391a89 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/ArrayExampleLong.avsc @@ -0,0 +1,3 @@ +{ + "type": "array", "items": "long" +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/EnumSchema.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/EnumSchema.avsc new file mode 100644 index 000000000..ea5c5b7b1 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/EnumSchema.avsc @@ -0,0 +1,5 @@ +{ + "type": "enum", + "name": "Suit", + "symbols" : ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"] +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/FixedSchema.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/FixedSchema.avsc new file mode 100644 index 000000000..4642ef577 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/FixedSchema.avsc @@ -0,0 +1,5 @@ +{ + "type" : "fixed", + "name" : "binaryData", + "size" : 64 +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc new file mode 100644 index 000000000..2db1d696d --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/HealthCheckBodyType.avsc @@ -0,0 +1,76 @@ +{ + "type" : "record", + "name" : "HealthCheckBody_Type", + "namespace" : "com.ericsson.apex.onap.tlgoal2017", + "fields" : [ + { + "name": "input", + "type": { + "type" : "record", + "name" : "InputRecord", + "fields" : [ + { + "name": "action", "type": "string" + }, + { + "name": "action_DasH_identifiers", + "type": { + "type" : "record", + "name" : "ActionIdentifiersRecord", + "fields" : [ + { + "name": "vnf_DasH_id", "type": "string" + } + ] + } + }, + { + "name": "common_DasH_header", + "type": { + "type" : "record", + "name" : "CommonHeaderRecord", + "fields" : [ + { + "name": "request_DasH_id", "type": "string" + }, + { + "name": "originator_DasH_id", "type": "string" + }, + { + "name": "api_DasH_ver", "type": "string" + }, + { + "name": "sub_DasH_request_DasH_id", "type": "string" + }, + { + "name": "timestamp", "type": "string" + }, + { + "name": "flags", + "type": { + "type" : "record", + "name" : "FlagsRecord", + "fields" : [ + { + "name": "ttl", "type": "string" + }, + { + "name": "force", "type": "string" + }, + { + "name": "mode", "type": "string" + } + ] + } + } + ] + } + }, + { + "name": "payload", "type": "string" + } + ] + } + } + ] +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc new file mode 100644 index 000000000..f8457c690 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddress.avsc @@ -0,0 +1,10 @@ +{ + "type": "map", "values": { + "type" : "record", + "name" : "AddressUSRecord", + "fields" : [ + {"name": "streetaddress", "type": "string"}, + {"name": "city", "type": "string"} + ] + } +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc new file mode 100644 index 000000000..48c476065 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleAddressInvalidFields.avsc @@ -0,0 +1,10 @@ +{ + "type": "map", "values": { + "type" : "record", + "name" : "AddressUSRecord", + "fields" : [ + {"name": "street_DasH_address", "type": "string"}, + {"name": "the_DoT_city", "type": "string"} + ] + } +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc new file mode 100644 index 000000000..0bb3729ed --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/MapExampleLong.avsc @@ -0,0 +1,3 @@ +{ + "type": "map", "values": "long" +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExample.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExample.avsc new file mode 100644 index 000000000..274735532 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExample.avsc @@ -0,0 +1,172 @@ +{ + "type": "record", + "name": "User", + "namespace": "com.example.avro", + "doc": "This is a user record in a fictitious to-do-list management app. It supports arbitrary grouping and nesting of items, and allows you to add items by email or by tweeting.\n\nNote this app doesn't actually exist. The schema is just a demo for [Avrodoc](https://github.com/ept/avrodoc)!", + "fields": [ + {"name": "firstname", "type": "string"}, + {"name": "lastname", "type": "string"}, + { + "name": "address", + "type": { + "type" : "record", + "name" : "AddressUSRecord", + "fields" : [ + {"name": "streetaddress", "type": "string"}, + {"name": "city", "type": "string"} + ] + } + }, + { + "name": "id", + "doc": "System-assigned numeric user ID. Cannot be changed by the user.", + "type": "int" + }, + { + "name": "username", + "doc": "The username chosen by the user. Can be changed by the user.", + "type": "string" + }, + { + "name": "passwordHash", + "doc": "The user's password, hashed using [scrypt](http://www.tarsnap.com/scrypt.html).", + "type": "string" + }, + { + "name": "signupDate", + "doc": "Timestamp (milliseconds since epoch) when the user signed up", + "type": "long" + }, + { + "name": "emailAddresses", + "doc": "All email addresses on the user's account", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "EmailAddress", + "doc": "Stores details about an email address that a user has associated with their account.", + "fields": [ + { + "name": "address", + "doc": "The email address, e.g. `foo@example.com`", + "type": "string" + }, + { + "name": "verified", + "doc": "true if the user has clicked the link in a confirmation email to this address.", + "type": "boolean", + "default": false + }, + { + "name": "dateAdded", + "doc": "Timestamp (milliseconds since epoch) when the email address was added to the account.", + "type": "long" + }, + { + "name": "dateBounced", + "doc": "Timestamp (milliseconds since epoch) when an email sent to this address last bounced. Reset to null when the address no longer bounces.", + "type": ["null", "long"] + } + ] + } + } + }, + { + "name": "twitterAccounts", + "doc": "All Twitter accounts that the user has OAuthed", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "TwitterAccount", + "doc": "Stores access credentials for one Twitter account, as granted to us by the user by OAuth.", + "fields": [ + { + "name": "status", + "doc": "Indicator of whether this authorization is currently active, or has been revoked", + "type": { + "type": "enum", + "name": "OAuthStatus", + "doc": "* `PENDING`: the user has started authorizing, but not yet finished\n* `ACTIVE`: the token should work\n* `DENIED`: the user declined the authorization\n* `EXPIRED`: the token used to work, but now it doesn't\n* `REVOKED`: the user has explicitly revoked the token", + "symbols": ["PENDING", "ACTIVE", "DENIED", "EXPIRED", "REVOKED"] + } + }, + { + "name": "userId", + "doc": "Twitter's numeric ID for this user", + "type": "long" + }, + { + "name": "screenName", + "doc": "The twitter username for this account (can be changed by the user)", + "type": "string" + }, + { + "name": "oauthToken", + "doc": "The OAuth token for this Twitter account", + "type": "string" + }, + { + "name": "oauthTokenSecret", + "doc": "The OAuth secret, used for signing requests on behalf of this Twitter account. `null` whilst the OAuth flow is not yet complete.", + "type": ["null", "string"] + }, + { + "name": "dateAuthorized", + "doc": "Timestamp (milliseconds since epoch) when the user last authorized this Twitter account", + "type": "long" + } + ] + } + } + }, + { + "name": "toDoItems", + "doc": "The top-level items in the user's to-do list", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "ToDoItem", + "doc": "A record is one node in a To-Do item tree (every record can contain nested sub-records).", + "fields": [ + { + "name": "status", + "doc": "User-selected state for this item (e.g. whether or not it is marked as done)", + "type": { + "type": "enum", + "name": "ToDoStatus", + "doc": "* `HIDDEN`: not currently visible, e.g. because it becomes actionable in future\n* `ACTIONABLE`: appears in the current to-do list\n* `DONE`: marked as done, but still appears in the list\n* `ARCHIVED`: marked as done and no longer visible\n* `DELETED`: not done and removed from list (preserved for undo purposes)", + "symbols": ["HIDDEN", "ACTIONABLE", "DONE", "ARCHIVED", "DELETED"] + } + }, + { + "name": "title", + "doc": "One-line summary of the item", + "type": "string" + }, + { + "name": "description", + "doc": "Detailed description (may contain HTML markup)", + "type": ["null", "string"] + }, + { + "name": "snoozeDate", + "doc": "Timestamp (milliseconds since epoch) at which the item should go from `HIDDEN` to `ACTIONABLE` status", + "type": ["null", "long"] + }, + { + "name": "subItems", + "doc": "List of children of this to-do tree node", + "type": { + "type": "array", + "items": "ToDoItem" + } + } + ] + } + } + } + ] +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc new file mode 100644 index 000000000..102641b44 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleInvalidFields.avsc @@ -0,0 +1,172 @@ +{ + "type": "record", + "name": "User", + "namespace": "com.example.avro", + "doc": "This is a user record in a fictitious to-do-list management app. It supports arbitrary grouping and nesting of items, and allows you to add items by email or by tweeting.\n\nNote this app doesn't actually exist. The schema is just a demo for [Avrodoc](https://github.com/ept/avrodoc)!", + "fields": [ + {"name": "firstname", "type": "string"}, + {"name": "lastname", "type": "string"}, + { + "name": "address", + "type": { + "type" : "record", + "name" : "AddressUSRecord", + "fields" : [ + {"name": "streetaddress_DasH_1", "type": "string"}, + {"name": "city", "type": "string"} + ] + } + }, + { + "name": "id", + "doc": "System-assigned numeric user ID. Cannot be changed by the user.", + "type": "int" + }, + { + "name": "username", + "doc": "The username chosen by the user. Can be changed by the user.", + "type": "string" + }, + { + "name": "passwordHash", + "doc": "The user's password, hashed using [scrypt](http://www.tarsnap.com/scrypt.html).", + "type": "string" + }, + { + "name": "signupDate", + "doc": "Timestamp (milliseconds since epoch) when the user signed up", + "type": "long" + }, + { + "name": "email_DoT_Addresses", + "doc": "All email addresses on the user's account", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "EmailAddress", + "doc": "Stores details about an email address that a user has associated with their account.", + "fields": [ + { + "name": "address", + "doc": "The email address, e.g. `foo@example.com`", + "type": "string" + }, + { + "name": "verified", + "doc": "true if the user has clicked the link in a confirmation email to this address.", + "type": "boolean", + "default": false + }, + { + "name": "dateAdded", + "doc": "Timestamp (milliseconds since epoch) when the email address was added to the account.", + "type": "long" + }, + { + "name": "dateBounced", + "doc": "Timestamp (milliseconds since epoch) when an email sent to this address last bounced. Reset to null when the address no longer bounces.", + "type": ["null", "long"] + } + ] + } + } + }, + { + "name": "twitterAccounts", + "doc": "All Twitter accounts that the user has OAuthed", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "TwitterAccount", + "doc": "Stores access credentials for one Twitter account, as granted to us by the user by OAuth.", + "fields": [ + { + "name": "status", + "doc": "Indicator of whether this authorization is currently active, or has been revoked", + "type": { + "type": "enum", + "name": "OAuthStatus", + "doc": "* `PENDING`: the user has started authorizing, but not yet finished\n* `ACTIVE`: the token should work\n* `DENIED`: the user declined the authorization\n* `EXPIRED`: the token used to work, but now it doesn't\n* `REVOKED`: the user has explicitly revoked the token", + "symbols": ["PENDING", "ACTIVE", "DENIED", "EXPIRED", "REVOKED"] + } + }, + { + "name": "userId", + "doc": "Twitter's numeric ID for this user", + "type": "long" + }, + { + "name": "screenName", + "doc": "The twitter username for this account (can be changed by the user)", + "type": "string" + }, + { + "name": "oauthToken", + "doc": "The OAuth token for this Twitter account", + "type": "string" + }, + { + "name": "oauthTokenSecret", + "doc": "The OAuth secret, used for signing requests on behalf of this Twitter account. `null` whilst the OAuth flow is not yet complete.", + "type": ["null", "string"] + }, + { + "name": "dateAuthorized", + "doc": "Timestamp (milliseconds since epoch) when the user last authorized this Twitter account", + "type": "long" + } + ] + } + } + }, + { + "name": "toDoItems", + "doc": "The top-level items in the user's to-do list", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "ToDoItem", + "doc": "A record is one node in a To-Do item tree (every record can contain nested sub-records).", + "fields": [ + { + "name": "status", + "doc": "User-selected state for this item (e.g. whether or not it is marked as done)", + "type": { + "type": "enum", + "name": "ToDoStatus", + "doc": "* `HIDDEN`: not currently visible, e.g. because it becomes actionable in future\n* `ACTIONABLE`: appears in the current to-do list\n* `DONE`: marked as done, but still appears in the list\n* `ARCHIVED`: marked as done and no longer visible\n* `DELETED`: not done and removed from list (preserved for undo purposes)", + "symbols": ["HIDDEN", "ACTIONABLE", "DONE", "ARCHIVED", "DELETED"] + } + }, + { + "name": "title_DasH_long", + "doc": "One-line summary of the item", + "type": "string" + }, + { + "name": "description", + "doc": "Detailed description (may contain HTML markup)", + "type": ["null", "string"] + }, + { + "name": "snoozeDate", + "doc": "Timestamp (milliseconds since epoch) at which the item should go from `HIDDEN` to `ACTIONABLE` status", + "type": ["null", "long"] + }, + { + "name": "subItems", + "doc": "List of children of this to-do tree node", + "type": { + "type": "array", + "items": "ToDoItem" + } + } + ] + } + } + } + ] +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc new file mode 100644 index 000000000..b9aac36f9 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPN.avsc @@ -0,0 +1,26 @@ +{ + "type" : "record", + "name" : "VPNActEvent", + "namespace" : "com.ericsson.apex.domains.vpn.events", + "fields" : [ + {"name": "nameSpace", "type": "string"}, + {"name": "name", "type": "string"}, + {"name": "version", "type": "string"}, + {"name": "source", "type": "string"}, + {"name": "target", "type": "string"}, + {"name": "LinkMap", "type": { + "type" : "record", + "name" : "LinkMap", + "namespace" : "com.ericsson.apex.domains.vpn", + "fields" : [ ] + } + }, + {"name": "CustomerMap", "type": { + "type" : "record", + "name" : "CustomerMap", + "namespace" : "com.ericsson.apex.domains.vpn", + "fields" : [ ] + } + } + ] +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc new file mode 100644 index 000000000..5936bb21f --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/RecordExampleVPNReuse.avsc @@ -0,0 +1,34 @@ +{ + "type" : "record", + "name" : "VPNActEvent", + "namespace" : "com.ericsson.apex.domains.vpn.events", + "fields" : [ + {"name": "nameSpace", "type": "string"}, + {"name": "name", "type": "string"}, + {"name": "version", "type": "string"}, + {"name": "source", "type": "string"}, + {"name": "target", "type": "string"}, + {"name": "LinkMap", "type": { + "type" : "record", + "name" : "LinkMap", + "namespace" : "com.ericsson.apex.domains.vpn", + "fields" : [ ] + } + }, + {"name": "CustomerMap", "type": { + "type" : "record", + "name" : "CustomerMap", + "namespace" : "com.ericsson.apex.domains.vpn", + "fields" : [ ] + } + }, + {"name": "CustomerMap1", "type": "com.ericsson.apex.domains.vpn.CustomerMap"}, + { + "name" : "CustomerMapArray", + "type": { + "type": "array", + "items": "com.ericsson.apex.domains.vpn.CustomerMap" + } + } + ] +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/UnionExample.avsc b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/UnionExample.avsc new file mode 100644 index 000000000..96b6050fb --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/avsc/UnionExample.avsc @@ -0,0 +1,30 @@ +{ + "namespace": "example.avro", + "type": "record", + "name": "User", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "favourite_number", + "type": [ + "null", + "int" + ] + }, + { + "name": "favourite_colour", + "type": [ + "null", + "string" + ] + }, + { + "name": "favourite_group", + "type": ["null", "string"], + "default": "null" + } + ] +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4Policy.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4Policy.json new file mode 100644 index 000000000..25ca3af8a --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4Policy.json @@ -0,0 +1,20 @@ +[ + { + "model-name": "service-instance", + "generic-vnf": { + "vnf-id": "de7cc3ab-0212-47df-9e64-da1c79234deb", + "vnf-name": "ZRDM2MMEX39", + "vnf-type": "vMME Svc Jul 14/vMME VF Jul 14 1", + "service-id": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "orchestration-status": "active", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1503082370097", + "model-invariant-id": "82194af1-3c2c-485a-8f44-420e22a9eaa4", + "model-version-id": "46b92144-923a-4d20-b85a-3cbd847668a9" + }, + "extra-properties": { + + } + } +] diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4VNF.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4VNF.json new file mode 100644 index 000000000..41cfc5c17 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponse4VNF.json @@ -0,0 +1,302 @@ +[ + { + "model-name": "vFW", + "generic-vnf": { + "vnf-id": "vFirewall_demo_app", + "vnf-name": "vFirewall_demo_app", + "vnf-type": "vFW", + "service-id": "vFirewall_demo_app", + "orchestration-status": "running", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509456799110", + "model-invariant-id": "vFirewall", + "model-version-id": "vFW" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "vserver": { + "vserver-id": "5b06cf36-40a0-4bcb-bde9-849aa4702d67", + "vserver-name": "vFW", + "vserver-name2": "vFW", + "prov-status": "Running", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/466979b815b5415ba14ada713e6e1846/servers/5b06cf36-40a0-4bcb-bde9-849aa4702d67", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509047869791" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "vnfc": { + "vnfc-name": "VNFC_vGMUX_demo_app2", + "nfc-naming-code": "vGMUXCODE2", + "nfc-function": "vGMUX", + "prov-status": "Running", + "orchestration-status": "Error", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509407048855" + }, + "extra-properties": { + + } + }, + { + "tenant": { + "tenant-id": "466979b815b5415ba14ada713e6e1846", + "tenant-name": "Integration", + "resource-version": "1508920100541" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "pod25", + "cloud-region-id": "RegionOne", + "identity-url": "http://10.12.25.2:5000/v3", + "sriov-automation": false, + "resource-version": "1509048416263" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "esr-system-info": { + "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29", + "system-name": "example-system-name-val-29070", + "type": "example-type-val-85254", + "vendor": "example-vendor-val-94515", + "version": "example-version-val-71880", + "service-url": "http://10.12.25.2:5000/v3", + "user-name": "demo", + "password": "onapdemo", + "system-type": "VIM", + "ssl-cacert": "example-ssl-cacert-val-75021", + "ssl-insecure": true, + "ip-address": "example-ip-address-val-44431", + "port": "example-port-val-93234", + "cloud-domain": "Default", + "default-tenant": "Integration", + "resource-version": "1508920101033" + }, + "extra-properties": { + + } + } + ] + } + } + ] + } + } + ] + } + }, + { + "vserver": { + "vserver-id": "0c52905c-f682-42cf-bd52-e7f8953e80e3", + "vserver-name": "vFW", + "vserver-name2": "vFW", + "prov-status": "Running", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/466979b815b5415ba14ada713e6e1846/servers/0c52905c-f682-42cf-bd52-e7f8953e80e3", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509047548567" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "vnfc": { + "vnfc-name": "VNFC_vGMUX_demo_app3", + "nfc-naming-code": "vGMUXCODE3", + "nfc-function": "vGMUX", + "prov-status": "Running", + "orchestration-status": "Running", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509041912808" + }, + "extra-properties": { + + } + }, + { + "tenant": { + "tenant-id": "466979b815b5415ba14ada713e6e1846", + "tenant-name": "Integration", + "resource-version": "1508920100541" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "pod25", + "cloud-region-id": "RegionOne", + "identity-url": "http://10.12.25.2:5000/v3", + "sriov-automation": false, + "resource-version": "1509048416263" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "esr-system-info": { + "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29", + "system-name": "example-system-name-val-29070", + "type": "example-type-val-85254", + "vendor": "example-vendor-val-94515", + "version": "example-version-val-71880", + "service-url": "http://10.12.25.2:5000/v3", + "user-name": "demo", + "password": "onapdemo", + "system-type": "VIM", + "ssl-cacert": "example-ssl-cacert-val-75021", + "ssl-insecure": true, + "ip-address": "example-ip-address-val-44431", + "port": "example-port-val-93234", + "cloud-domain": "Default", + "default-tenant": "Integration", + "resource-version": "1508920101033" + }, + "extra-properties": { + + } + } + ] + } + } + ] + } + } + ] + } + }, + { + "vserver": { + "vserver-id": "33e16e02-098a-4f4e-a37f-b4e0307596c0", + "vserver-name": "vFW", + "vserver-name2": "vFW", + "prov-status": "Running", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/466979b815b5415ba14ada713e6e1846/servers/33e16e02-098a-4f4e-a37f-b4e0307596c0", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509047285114" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "vnfc": { + "vnfc-name": "vnfc-related-to-vserver-example", + "nfc-naming-code": "example-nfc-naming-code-val-78172", + "nfc-function": "example-nfc-function-val-56352", + "prov-status": "example-prov-status-val-10699", + "orchestration-status": "example-orchestration-status-val-68896", + "ipaddress-v4-oam-vip": "example-ipaddress-v4-oam-vip-val-71483", + "in-maint": true, + "is-closed-loop-disabled": true, + "group-notation": "example-group-notation-val-31912", + "resource-version": "1508800709772" + }, + "extra-properties": { + + } + }, + { + "vnfc": { + "vnfc-name": "VNFC_vGMUX_demo_app", + "nfc-naming-code": "vGMUXCODE", + "nfc-function": "vGMUX", + "prov-status": "Running", + "orchestration-status": "Running", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1509041573965" + }, + "extra-properties": { + + } + }, + { + "tenant": { + "tenant-id": "466979b815b5415ba14ada713e6e1846", + "tenant-name": "Integration", + "resource-version": "1508920100541" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "pod25", + "cloud-region-id": "RegionOne", + "identity-url": "http://10.12.25.2:5000/v3", + "sriov-automation": false, + "resource-version": "1509048416263" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "esr-system-info": { + "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29", + "system-name": "example-system-name-val-29070", + "type": "example-type-val-85254", + "vendor": "example-vendor-val-94515", + "version": "example-version-val-71880", + "service-url": "http://10.12.25.2:5000/v3", + "user-name": "demo", + "password": "onapdemo", + "system-type": "VIM", + "ssl-cacert": "example-ssl-cacert-val-75021", + "ssl-insecure": true, + "ip-address": "example-ip-address-val-44431", + "port": "example-port-val-93234", + "cloud-domain": "Default", + "default-tenant": "Integration", + "resource-version": "1508920101033" + }, + "extra-properties": { + + } + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } +] diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponseExample.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponseExample.json new file mode 100644 index 000000000..a1a1e19bc --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/AAIResponseExample.json @@ -0,0 +1,209 @@ +{ + "inventory-response-item": [ + { + "vserver": { + "vserver-id": "6ed3642c-f7a1-4a7c-9290-3d51fe1531eb", + "vserver-name": "zdfw1lb01lb02", + "vserver-name2": "zdfw1lb01lb02", + "prov-status": "ACTIVE", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/41d6d38489bd40b09ea8a6b6b852dcbd/servers/6ed3642c-f7a1-4a7c-9290-3d51fe1531eb", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1510606403522" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "model-name": "vLoadBalancer", + "generic-vnf": { + "vnf-id": "db373a8d-f7be-4d02-8ac8-6ca4c305d144", + "vnf-name": "Vfmodule_vLB1113", + "vnf-type": "vLoadBalancer-1106/vLoadBalancer 0", + "service-id": "66f157fc-4148-4880-95f5-e120677e98d1", + "prov-status": "PREPROV", + "orchestration-status": "Created", + "in-maint": false, + "is-closed-loop-disabled": false, + "resource-version": "1510604011851", + "model-invariant-id": "cee050ed-92a5-494f-ab04-234307a846dc", + "model-version-id": "fd65becc-6b2c-4fe8-ace9-cc29db9a3da2", + "model-customization-id": "1983c783-444f-4e79-af3a-85e5d49628f3", + "nf-type": "", + "nf-function": "", + "nf-role": "", + "nf-naming-code": "" + }, + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "fd65becc-6b2c-4fe8-ace9-cc29db9a3da2" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancer" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "cee050ed-92a5-494f-ab04-234307a846dc" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "model-name": "vLoadBalancer-1106", + "service-instance": { + "service-instance-id": "3b12f31f-8f2d-4f5c-b875-61ff1194b941", + "service-instance-name": "vLoadBalancer-1113", + "model-invariant-id": "1321d60d-f7ff-4300-96c2-6bf0b3268b7a", + "model-version-id": "732d4692-4b97-46f9-a996-0b3339e88c50", + "resource-version": "1510603936425" + }, + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "732d4692-4b97-46f9-a996-0b3339e88c50" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancer-1106" + }, + { + "property-name": "model.model-type", + "property-value": "service" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "1321d60d-f7ff-4300-96c2-6bf0b3268b7a" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + } + }, + { + "model-name": "Vloadbalancer..base_vlb..module-0", + "vf-module": { + "vf-module-id": "e6b3e3eb-34e1-4c00-b8c1-2a4fbe479b12", + "vf-module-name": "Vfmodule_vLB1113-1", + "heat-stack-id": "Vfmodule_vLB1113-1/3dd6d900-772f-4fcc-a0cb-e250ab2bb4db", + "orchestration-status": "active", + "is-base-vf-module": true, + "resource-version": "1510604612557", + "model-invariant-id": "6d760188-9a24-451a-b05b-e08b86cb94f2", + "model-version-id": "93facad9-55f2-4fe0-9574-814c2bc2d071", + "model-customization-id": "93fd5bd4-8051-4074-8530-c0c504604df5", + "module-index": 0 + }, + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "93facad9-55f2-4fe0-9574-814c2bc2d071" + }, + { + "property-name": "model-ver.model-name", + "property-value": "Vloadbalancer..base_vlb..module-0" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "6d760188-9a24-451a-b05b-e08b86cb94f2" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1" + } + ] + } + }, + { + "model-name": "Vloadbalancer..dnsscaling..module-1", + "vf-module": { + "vf-module-id": "dummy_db373a8d-f7be-4d02-8ac8-6ca4c305d144", + "vf-module-name": "dummy_db373a8d-f7be-4d02-8ac8-6ca4c305d144", + "is-base-vf-module": false, + "resource-version": "1510610079687", + "model-invariant-id": "356a1cff-71f2-4086-9980-a2927ce11c1c", + "model-version-id": "6b93d804-cfc8-4be3-92cc-9336d135859a" + }, + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "6b93d804-cfc8-4be3-92cc-9336d135859a" + }, + { + "property-name": "model-ver.model-name", + "property-value": "Vloadbalancer..dnsscaling..module-1" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "356a1cff-71f2-4086-9980-a2927ce11c1c" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1" + } + ] + } + } + ] + } + }, + { + "tenant": { + "tenant-id": "41d6d38489bd40b09ea8a6b6b852dcbd", + "tenant-name": "Integration-SB-00", + "resource-version": "1509587770200" + }, + "extra-properties": { + + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "CloudOwner", + "cloud-region-id": "RegionOne", + "cloud-type": "SharedNode", + "owner-defined-type": "OwnerType", + "cloud-region-version": "v1", + "cloud-zone": "CloudZone", + "sriov-automation": false, + "resource-version": "1509587770092" + }, + "extra-properties": { + + } + } + ] + } + } + ] + } + } + ] +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json new file mode 100644 index 000000000..9ad632a8f --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressFull.json @@ -0,0 +1,13 @@ +[ { + "streetaddress" : "1600 Pennsylvania Avenue", + "city" : "Washington DC" +}, { + "streetaddress" : "Somewhere", + "city" : "Over the rainbow" +}, { + "streetaddress" : "221 B Baker St.", + "city" : "London" +}, { + "streetaddress" : "Wayne Manor", + "city" : "Gotham City" +} ] \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json new file mode 100644 index 000000000..8878e547a --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleAddressNull.json @@ -0,0 +1 @@ +[ ] \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json new file mode 100644 index 000000000..ca12244ee --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongFull.json @@ -0,0 +1 @@ +[ 9223372036854775807, -3, -2, 1, -9223372036854775808, -67890, 5, 0 ] \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json new file mode 100644 index 000000000..8878e547a --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/ArrayExampleLongNull.json @@ -0,0 +1 @@ +[ ] \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad0.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad0.json new file mode 100644 index 000000000..d1218ca59 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad0.json @@ -0,0 +1 @@ +"TWEED" \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad1.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad1.json new file mode 100644 index 000000000..67b3fe5c7 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleBad1.json @@ -0,0 +1 @@ +"Hearts" \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleHearts.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleHearts.json new file mode 100644 index 000000000..92bd68a7e --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleHearts.json @@ -0,0 +1 @@ +"HEARTS" \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleNull.json new file mode 100644 index 000000000..ec747fa47 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/EnumExampleNull.json @@ -0,0 +1 @@ +null \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad0.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad0.json new file mode 100644 index 000000000..f0251f122 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad0.json @@ -0,0 +1 @@ +"BADBAD" \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad1.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad1.json new file mode 100644 index 000000000..687d14210 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleBad1.json @@ -0,0 +1 @@ +"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0" \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleGood.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleGood.json new file mode 100644 index 000000000..846002e51 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleGood.json @@ -0,0 +1 @@ +"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleNull.json new file mode 100644 index 000000000..ec747fa47 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/FixedExampleNull.json @@ -0,0 +1 @@ +null \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/HealthCheckEvent.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/HealthCheckEvent.json new file mode 100644 index 000000000..4233f3b57 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/HealthCheckEvent.json @@ -0,0 +1,22 @@ +{ + "input": { + "action": "HealthCheck", + "action-identifiers": { + "vnf-id": "49414df5-3482-4fd8-9952-c463dff2770b" + }, + "common-header": { + "request-id": "afr-request3", + "originator-id": "AFR", + "api-ver": "2.15", + "sub-request-id": "AFR-subrequest", + "timestamp": "2017-11-06T15:15:18.97Z", + "flags": { + "ttl": "10000", + "force": "TRUE", + "mode": "EXCLUSIVE" + } + }, + "payload": "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\",\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}" + } +} + diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressFull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressFull.json new file mode 100644 index 000000000..2a1911445 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressFull.json @@ -0,0 +1,18 @@ +{ + "address0" : { + "streetaddress" : "1600 Pennsylvania Avenue", + "city" : "Washington DC" + }, + "address1" : { + "streetaddress" : "Somewhere", + "city" : "Over the rainbow" + }, + "address2" : { + "streetaddress" : "221 B Baker St.", + "city" : "London" + }, + "address3" : { + "streetaddress" : "Wayne Manor", + "city" : "Gotham City" + } +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json new file mode 100644 index 000000000..fa23c8328 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressInvalidFields.json @@ -0,0 +1,18 @@ +{ + "address.0" : { + "street-address" : "1600 Pennsylvania Avenue", + "the.city" : "Washington DC" + }, + "address.1" : { + "street-address" : "Somewhere", + "the.city" : "Over the rainbow" + }, + "address.2" : { + "street-address" : "221 B Baker St.", + "the.city" : "London" + }, + "address.3" : { + "street-address" : "Wayne Manor", + "the.city" : "Gotham City" + } +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressNull.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleAddressNull.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongFull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongFull.json new file mode 100644 index 000000000..f94a4f600 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongFull.json @@ -0,0 +1,10 @@ +{ + "key04" : 9223372036854775807, + "key03" : -3, + "key02" : -2, + "key01" : 1, + "key07" : -9223372036854775808, + "key06" : -67890, + "key05" : 5, + "key00" : 0 +} diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongNull.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/MapExampleLongNull.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleFull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleFull.json new file mode 100644 index 000000000..d4fbf106a --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleFull.json @@ -0,0 +1,41 @@ +{ + "firstname" : "Liam", + "lastname" : "Fallon", + "address" : { + "streetaddress" : "Somewhere", + "city" : "Over the rainbow" + }, + "id" : 1497, + "username" : "eeilfn", + "passwordHash" : "gobbledygook", + "signupDate" : 894614400, + "emailAddresses" : [ { + "address" : "sean@citizen.ie", + "verified" : true, + "dateAdded" : 1495805460, + "dateBounced" : { + "long" : 1495805460 + } + } ], + "twitterAccounts" : [ { + "status" : "ACTIVE", + "userId" : 12345, + "screenName" : "Zooby", + "oauthToken" : "ZoobyOToken", + "oauthTokenSecret" : { + "string" : "ZoobyOTokenSecret" + }, + "dateAuthorized" : 149580546 + } ], + "toDoItems" : [ { + "status" : "DONE", + "title" : "fierce important thing", + "description" : { + "string" : "Description of fierce important thing" + }, + "snoozeDate" : { + "long" : 149580567 + }, + "subItems" : [ ] + } ] +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json new file mode 100644 index 000000000..f40075e27 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleInvalidFields.json @@ -0,0 +1,41 @@ +{ + "firstname" : "Liam", + "lastname" : "Fallon", + "address" : { + "streetaddress-1" : "Somewhere", + "city" : "Over the rainbow" + }, + "id" : 1497, + "username" : "eeilfn", + "passwordHash" : "gobbledygook", + "signupDate" : 894614400, + "email.Addresses" : [ { + "address" : "sean@citizenie", + "verified" : true, + "dateAdded" : 1495805460, + "dateBounced" : { + "long" : 1495805460 + } + } ], + "twitterAccounts" : [ { + "status" : "ACTIVE", + "userId" : 12345, + "screenName" : "Zooby", + "oauthToken" : "ZoobyOToken", + "oauthTokenSecret" : { + "string" : "ZoobyOTokenSecret" + }, + "dateAuthorized" : 149580546 + } ], + "toDoItems" : [ { + "status" : "DONE", + "title-long" : "fierce important thing", + "description" : { + "string" : "Description of fierce important thing" + }, + "snoozeDate" : { + "long" : 149580567 + }, + "subItems" : [ ] + } ] +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleNull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleNull.json new file mode 100644 index 000000000..03eef6c05 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleNull.json @@ -0,0 +1,15 @@ +{ + "firstname" : "", + "lastname" : "", + "address" : { + "streetaddress" : "", + "city" : "" + }, + "id" : 0, + "username" : "", + "passwordHash" : "", + "signupDate" : 0, + "emailAddresses" : [ ], + "twitterAccounts" : [ ], + "toDoItems" : [ ] +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json new file mode 100644 index 000000000..7e4da3391 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/RecordExampleVPNFull.json @@ -0,0 +1,9 @@ +{ + "nameSpace" : "com.ericsson.apex.domains.vpn.events", + "name" : "VPNTriggerEvent", + "version" : "0.0.1", + "source" : "VPNSLA", + "target" : "Apex", + "LinkMap" : { }, + "CustomerMap" : { } +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleAllFields.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleAllFields.json new file mode 100644 index 000000000..88299e3a4 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleAllFields.json @@ -0,0 +1,6 @@ +{ + "name" : "Ben", + "favourite_number" : 7, + "favourite_colour" : "red", + "favourite_group" : "Zooby" +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleNullField.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleNullField.json new file mode 100644 index 000000000..4fd33a6eb --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleNullField.json @@ -0,0 +1,6 @@ +{ + "name": "Alyssa", + "favourite_number": 256, + "favourite_colour": null, + "favourite_group": "U2" +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json new file mode 100644 index 000000000..f62d25b31 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/data/UnionExampleOptionalField.json @@ -0,0 +1,5 @@ +{ + "name": "Claire", + "favourite_number": 123, + "favourite_colour": null +} \ No newline at end of file diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/logback-test.xml b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/logback-test.xml new file mode 100644 index 000000000..3dd11e9cb --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/resources/logback-test.xml @@ -0,0 +1,74 @@ + + + + + + Apex + + + + + + + %d %contextName [%t] %level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + ${LOG_DIR}/apex.log + + %d %-5relative [procId=${processId}] [%thread] %-5level + %logger{26} - %msg %n %ex{full} + + + + + ${LOG_DIR}/apex_ctxt.log + + %d %-5relative [procId=${processId}] [%thread] %-5level + %logger{26} - %msg %n %ex{full} + + + + + + + + + + + + + + + diff --git a/plugins/plugins-context/plugins-context-schema/pom.xml b/plugins/plugins-context/plugins-context-schema/pom.xml new file mode 100644 index 000000000..f515c2015 --- /dev/null +++ b/plugins/plugins-context/plugins-context-schema/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.onap.policy.apex-pdp.plugins.plugins-context + plugins-context + 2.0.0-SNAPSHOT + + + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema + plugins-context-schema + pom + + ${project.artifactId} + Plugins for 3pps that handle context schemas + + plugins-context-schema-avro + + diff --git a/plugins/plugins-context/pom.xml b/plugins/plugins-context/pom.xml index 8e3c72870..d3d2963e6 100644 --- a/plugins/plugins-context/pom.xml +++ b/plugins/plugins-context/pom.xml @@ -42,10 +42,10 @@ - context-schema - context-distribution - context-locking - context-persistence + plugins-context-schema + plugins-context-distribution + plugins-context-locking + plugins-context-persistence - \ No newline at end of file + diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml index c44b09fd6..b40aab498 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/pom.xml @@ -40,11 +40,5 @@ snakeyaml 1.21 - - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema-avro - ${project.version} - test - diff --git a/testsuites/integration/integration-context-test/pom.xml b/testsuites/integration/integration-context-test/pom.xml index 8c62339f2..6454a8cd5 100644 --- a/testsuites/integration/integration-context-test/pom.xml +++ b/testsuites/integration/integration-context-test/pom.xml @@ -40,18 +40,18 @@ test - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-hazelcast + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-hazelcast ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-infinispan + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-infinispan ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking-curator + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking-curator ${project.version} @@ -61,8 +61,8 @@ - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking-hazelcast + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking-hazelcast ${project.version} @@ -85,4 +85,4 @@ - \ No newline at end of file + diff --git a/testsuites/integration/integration-uservice-test/pom.xml b/testsuites/integration/integration-uservice-test/pom.xml index 8fbafb604..427f70f27 100644 --- a/testsuites/integration/integration-uservice-test/pom.xml +++ b/testsuites/integration/integration-uservice-test/pom.xml @@ -53,8 +53,8 @@ test - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema-avro + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema + plugins-context-schema-avro ${project.version} test @@ -71,8 +71,8 @@ test - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-infinispan + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-infinispan ${project.version} test diff --git a/testsuites/performance/performance-benchmark-test/pom.xml b/testsuites/performance/performance-benchmark-test/pom.xml index 118fe115c..938884762 100644 --- a/testsuites/performance/performance-benchmark-test/pom.xml +++ b/testsuites/performance/performance-benchmark-test/pom.xml @@ -72,8 +72,8 @@ test - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema-avro + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema + plugins-context-schema-avro ${project.version} test @@ -96,4 +96,4 @@ - \ No newline at end of file + diff --git a/testsuites/performance/performance-context-metrics/pom.xml b/testsuites/performance/performance-context-metrics/pom.xml index 4f6eabf56..830e6ad54 100644 --- a/testsuites/performance/performance-context-metrics/pom.xml +++ b/testsuites/performance/performance-context-metrics/pom.xml @@ -43,23 +43,23 @@ ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-hazelcast + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-hazelcast ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-distribution - context-distribution-infinispan + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution + plugins-context-distribution-infinispan ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking-curator + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking-curator ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-locking - context-locking-hazelcast + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking + plugins-context-locking-hazelcast ${project.version} @@ -69,4 +69,4 @@ test - \ No newline at end of file + diff --git a/tools/model-generator/pom.xml b/tools/model-generator/pom.xml index 2cdc7c20f..5da446c77 100644 --- a/tools/model-generator/pom.xml +++ b/tools/model-generator/pom.xml @@ -47,8 +47,8 @@ ${project.version} - org.onap.policy.apex-pdp.plugins.plugins-context.context-schema - context-schema-avro + org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema + plugins-context-schema-avro ${project.version} @@ -57,4 +57,4 @@ ${project.version} - \ No newline at end of file + -- cgit 1.2.3-korg