From e37de6e66c5cc554384a1f27f68f4d27962fe15d Mon Sep 17 00:00:00 2001 From: Lisa Revel Date: Mon, 20 Feb 2017 19:15:19 +0000 Subject: Re-add source from correct branch Change-Id: I515f8378ea1d2baf0aa2434ec46272f1b5bdb229 Signed-off-by: Lisa Revel --- README.md | 7 + cpd-exclude.properties | 3 +- dcae-analytics-common/pom.xml | 6 +- .../dcae/analytics/common/AnalyticsConstants.java | 134 ---- .../analytics/common/CDAPComponentsConstants.java | 196 ----- .../analytics/common/CDAPMetricsConstants.java | 112 --- .../analytics/common/DCAEAnalyticsPreferences.java | 29 - .../common/cdap/settings/CDAPAppConfig.java | 47 -- .../common/cdap/settings/CDAPAppPreferences.java | 31 - .../common/cdap/settings/CDAPAppSettings.java | 35 - .../common/cdap/settings/CDAPBaseAppConfig.java | 62 -- .../cdap/validation/CDAPAppSettingsValidator.java | 52 -- .../common/exception/CDAPSettingsException.java | 50 -- .../exception/DCAEAnalyticsRuntimeException.java | 54 -- .../exception/MessageProcessingException.java | 51 -- .../processor/AbstractMessageProcessor.java | 162 ---- .../processor/AbstractProcessorContext.java | 96 --- .../processor/GenericMessageChainProcessor.java | 63 -- .../service/processor/GenericProcessorInfo.java | 55 -- .../common/service/processor/MessageProcessor.java | 84 --- .../common/service/processor/ProcessingState.java | 36 - .../common/service/processor/ProcessorContext.java | 70 -- .../common/service/processor/ProcessorInfo.java | 49 -- .../dcae/analytics/common/utils/HTTPUtils.java | 57 -- .../common/utils/MessageProcessorUtils.java | 114 --- .../analytics/common/utils/PersistenceUtils.java | 54 -- .../analytics/common/utils/ValidationUtils.java | 89 --- .../analytics/common/validation/DCAEValidator.java | 29 - .../validation/GenericValidationResponse.java | 84 --- .../common/validation/ValidationResponse.java | 90 --- .../apod/analytics/common/AnalyticsConstants.java | 134 ++++ .../analytics/common/CDAPComponentsConstants.java | 196 +++++ .../analytics/common/CDAPMetricsConstants.java | 112 +++ .../analytics/common/DCAEAnalyticsPreferences.java | 29 + .../common/cdap/settings/CDAPAppConfig.java | 47 ++ .../common/cdap/settings/CDAPAppPreferences.java | 31 + .../common/cdap/settings/CDAPAppSettings.java | 35 + .../common/cdap/settings/CDAPBaseAppConfig.java | 62 ++ .../cdap/validation/CDAPAppSettingsValidator.java | 52 ++ .../common/exception/CDAPSettingsException.java | 50 ++ .../exception/DCAEAnalyticsRuntimeException.java | 54 ++ .../exception/MessageProcessingException.java | 51 ++ .../processor/AbstractMessageProcessor.java | 162 ++++ .../processor/AbstractProcessorContext.java | 96 +++ .../processor/GenericMessageChainProcessor.java | 63 ++ .../service/processor/GenericProcessorInfo.java | 55 ++ .../common/service/processor/MessageProcessor.java | 84 +++ .../common/service/processor/ProcessingState.java | 36 + .../common/service/processor/ProcessorContext.java | 70 ++ .../common/service/processor/ProcessorInfo.java | 49 ++ .../apod/analytics/common/utils/HTTPUtils.java | 57 ++ .../common/utils/MessageProcessorUtils.java | 114 +++ .../analytics/common/utils/PersistenceUtils.java | 54 ++ .../analytics/common/utils/ValidationUtils.java | 89 +++ .../analytics/common/validation/DCAEValidator.java | 29 + .../validation/GenericValidationResponse.java | 84 +++ .../common/validation/ValidationResponse.java | 90 +++ .../common/BaseAnalyticsCommonUnitTest.java | 48 -- .../GenericMessageChainProcessorTest.java | 96 --- .../processor/TestEarlyTerminatingProcessor.java | 39 - .../service/processor/TestMessageProcessor1.java | 41 - .../service/processor/TestMessageProcessor2.java | 41 - .../service/processor/TestProcessorContext.java | 84 --- .../common/BaseAnalyticsCommonUnitTest.java | 48 ++ .../GenericMessageChainProcessorTest.java | 96 +++ .../processor/TestEarlyTerminatingProcessor.java | 39 + .../service/processor/TestMessageProcessor1.java | 41 + .../service/processor/TestMessageProcessor2.java | 41 + .../service/processor/TestProcessorContext.java | 84 +++ dcae-analytics-dmaap/pom.xml | 6 +- .../dcae/analytics/dmaap/DMaaPMRFactory.java | 112 --- .../dmaap/domain/config/DMaaPMRBaseConfig.java | 193 ----- .../dmaap/domain/config/DMaaPMRConfig.java | 38 - .../domain/config/DMaaPMRPublisherConfig.java | 250 ------- .../domain/config/DMaaPMRSubscriberConfig.java | 298 -------- .../domain/response/DMaaPMRPublisherResponse.java | 38 - .../response/DMaaPMRPublisherResponseImpl.java | 70 -- .../dmaap/domain/response/DMaaPMRResponse.java | 46 -- .../domain/response/DMaaPMRSubscriberResponse.java | 40 - .../response/DMaaPMRSubscriberResponseImpl.java | 80 -- .../dmaap/module/AnalyticsDMaaPModule.java | 62 -- .../dmaap/service/BaseDMaaPMRComponent.java | 356 --------- .../analytics/dmaap/service/DMaaPMRComponent.java | 29 - .../dmaap/service/publisher/DMaaPMRPublisher.java | 96 --- .../service/publisher/DMaaPMRPublisherFactory.java | 42 -- .../service/publisher/DMaaPMRPublisherImpl.java | 211 ------ .../service/publisher/DMaaPMRPublisherQueue.java | 89 --- .../publisher/DMaaPMRPublisherQueueFactory.java | 37 - .../publisher/DMaaPMRPublisherQueueImpl.java | 124 ---- .../service/subscriber/DMaaPMRSubscriber.java | 60 -- .../subscriber/DMaaPMRSubscriberFactory.java | 40 - .../service/subscriber/DMaaPMRSubscriberImpl.java | 129 ---- .../dcae/apod/analytics/dmaap/DMaaPMRFactory.java | 112 +++ .../dmaap/domain/config/DMaaPMRBaseConfig.java | 193 +++++ .../dmaap/domain/config/DMaaPMRConfig.java | 38 + .../domain/config/DMaaPMRPublisherConfig.java | 250 +++++++ .../domain/config/DMaaPMRSubscriberConfig.java | 298 ++++++++ .../domain/response/DMaaPMRPublisherResponse.java | 38 + .../response/DMaaPMRPublisherResponseImpl.java | 70 ++ .../dmaap/domain/response/DMaaPMRResponse.java | 46 ++ .../domain/response/DMaaPMRSubscriberResponse.java | 40 + .../response/DMaaPMRSubscriberResponseImpl.java | 80 ++ .../dmaap/module/AnalyticsDMaaPModule.java | 62 ++ .../dmaap/service/BaseDMaaPMRComponent.java | 356 +++++++++ .../analytics/dmaap/service/DMaaPMRComponent.java | 29 + .../dmaap/service/publisher/DMaaPMRPublisher.java | 96 +++ .../service/publisher/DMaaPMRPublisherFactory.java | 42 ++ .../service/publisher/DMaaPMRPublisherImpl.java | 211 ++++++ .../service/publisher/DMaaPMRPublisherQueue.java | 89 +++ .../publisher/DMaaPMRPublisherQueueFactory.java | 37 + .../publisher/DMaaPMRPublisherQueueImpl.java | 124 ++++ .../service/subscriber/DMaaPMRSubscriber.java | 60 ++ .../subscriber/DMaaPMRSubscriberFactory.java | 40 + .../service/subscriber/DMaaPMRSubscriberImpl.java | 129 ++++ .../dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java | 31 - .../dmaap/BaseAnalyticsDMaaPUnitTest.java | 99 --- .../dcae/analytics/dmaap/DMaaPMRFactoryTest.java | 67 -- .../domain/config/DMaaPMRPublisherConfigTest.java | 86 --- .../domain/config/DMaaPMRSubscriberConfigTest.java | 91 --- .../analytics/dmaap/it/BaseAnalyticsDMaaPIT.java | 110 --- .../analytics/dmaap/it/DMaaPMRPublisherImplIT.java | 56 -- .../dmaap/it/DMaaPMRSubscriberImplIT.java | 85 --- .../dmaap/module/AnalyticsDMaaPTestModule.java | 60 -- .../dmaap/service/BaseDMaaPMRComponentTest.java | 340 --------- .../publisher/DMaaPMRPublisherImplTest.java | 212 ------ .../publisher/DMaaPMRPublisherMockImpl.java | 59 -- .../publisher/DMaaPMRPublisherQueueImplTest.java | 189 ----- .../publisher/DMaaPMRPublisherQueueMockImpl.java | 53 -- .../subscriber/DMaaPMRSubscriberImplTest.java | 158 ---- .../subscriber/DMaaPMRSubscriberMockImpl.java | 48 -- .../dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java | 31 + .../dmaap/BaseAnalyticsDMaaPUnitTest.java | 99 +++ .../apod/analytics/dmaap/DMaaPMRFactoryTest.java | 67 ++ .../domain/config/DMaaPMRPublisherConfigTest.java | 86 +++ .../domain/config/DMaaPMRSubscriberConfigTest.java | 91 +++ .../analytics/dmaap/it/BaseAnalyticsDMaaPIT.java | 110 +++ .../analytics/dmaap/it/DMaaPMRPublisherImplIT.java | 56 ++ .../dmaap/it/DMaaPMRSubscriberImplIT.java | 85 +++ .../dmaap/module/AnalyticsDMaaPTestModule.java | 60 ++ .../dmaap/service/BaseDMaaPMRComponentTest.java | 340 +++++++++ .../publisher/DMaaPMRPublisherImplTest.java | 212 ++++++ .../publisher/DMaaPMRPublisherMockImpl.java | 59 ++ .../publisher/DMaaPMRPublisherQueueImplTest.java | 189 +++++ .../publisher/DMaaPMRPublisherQueueMockImpl.java | 53 ++ .../subscriber/DMaaPMRSubscriberImplTest.java | 158 ++++ .../subscriber/DMaaPMRSubscriberMockImpl.java | 48 ++ dcae-analytics-model/pom.xml | 4 +- .../domain/BaseDynamicPropertiesProvider.java | 64 -- .../analytics/model/domain/DCAEAnalyticsModel.java | 28 - .../model/domain/DynamicPropertiesProvider.java | 41 - .../analytics/model/domain/cef/AlertAction.java | 28 - .../dcae/analytics/model/domain/cef/AlertType.java | 41 - .../analytics/model/domain/cef/BaseCEFModel.java | 37 - .../dcae/analytics/model/domain/cef/CEFModel.java | 30 - .../model/domain/cef/CommonEventHeader.java | 113 --- .../analytics/model/domain/cef/Criticality.java | 27 - .../dcae/analytics/model/domain/cef/Event.java | 59 -- .../analytics/model/domain/cef/EventListener.java | 42 -- .../analytics/model/domain/cef/EventSeverity.java | 32 - .../domain/cef/MeasurementsForVfScalingFields.java | 53 -- .../model/domain/cef/PerformanceCounter.java | 61 -- .../dcae/analytics/model/domain/cef/Priority.java | 28 - .../domain/cef/ThresholdCrossingAlertFields.java | 157 ---- .../analytics/model/domain/cef/VNicUsageArray.java | 75 -- .../analytics/model/domain/policy/PolicyModel.java | 29 - .../domain/policy/tca/BaseTCAPolicyModel.java | 33 - .../model/domain/policy/tca/Direction.java | 52 -- .../policy/tca/MetricsPerFunctionalRole.java | 77 -- .../model/domain/policy/tca/TCAPolicy.java | 55 -- .../model/domain/policy/tca/TCAPolicyModel.java | 31 - .../model/domain/policy/tca/Threshold.java | 82 -- .../dcae/analytics/model/facade/FacadeModel.java | 29 - .../dcae/analytics/model/facade/tca/AAI.java | 34 - .../analytics/model/facade/tca/TCAFacadeModel.java | 27 - .../analytics/model/facade/tca/TCAVESResponse.java | 45 -- .../model/util/AnalyticsModelIOUtils.java | 142 ---- .../model/util/AnalyticsModelJsonUtils.java | 100 --- .../json/AnalyticsModelObjectMapperSupplier.java | 108 --- .../model/util/json/CommonEventFormatModule.java | 80 -- .../model/util/json/TCAFacadeModelModule.java | 45 -- .../analytics/model/util/json/TCAPolicyModule.java | 57 -- .../mixin/BaseDynamicPropertiesProviderMixin.java | 41 - .../analytics/model/util/json/mixin/JsonMixin.java | 27 - .../util/json/mixin/cef/AlertActionMixin.java | 26 - .../model/util/json/mixin/cef/AlertTypeMixin.java | 57 -- .../util/json/mixin/cef/BaseCEFModelMixin.java | 29 - .../json/mixin/cef/CommonEventHeaderMixin.java | 23 - .../util/json/mixin/cef/CriticalityMixin.java | 26 - .../util/json/mixin/cef/EventListenerMixin.java | 27 - .../model/util/json/mixin/cef/EventMixin.java | 27 - .../util/json/mixin/cef/EventSeverityMixin.java | 26 - .../cef/MeasurementsForVfScalingFieldsMixin.java | 35 - .../json/mixin/cef/PerformanceCounterMixin.java | 25 - .../model/util/json/mixin/cef/PriorityMixin.java | 26 - .../cef/ThresholdCrossingAlertFieldsMixin.java | 25 - .../util/json/mixin/cef/VNicUsageArrayMixin.java | 32 - .../model/util/json/mixin/facade/tca/AAIMixin.java | 50 -- .../facade/tca/VESCEFMessageResponseMixin.java | 52 -- .../mixin/policy/tca/BaseTCAPolicyModelMixin.java | 26 - .../util/json/mixin/policy/tca/DirectionMixin.java | 26 - .../policy/tca/MetricsPerFunctionalRoleMixin.java | 24 - .../util/json/mixin/policy/tca/TCAPolicyMixin.java | 24 - .../util/json/mixin/policy/tca/ThresholdMixin.java | 24 - .../domain/BaseDynamicPropertiesProvider.java | 68 ++ .../analytics/model/domain/DCAEAnalyticsModel.java | 32 + .../model/domain/DynamicPropertiesProvider.java | 45 ++ .../analytics/model/domain/cef/AlertAction.java | 32 + .../apod/analytics/model/domain/cef/AlertType.java | 45 ++ .../analytics/model/domain/cef/BaseCEFModel.java | 41 + .../apod/analytics/model/domain/cef/CEFModel.java | 34 + .../model/domain/cef/CommonEventHeader.java | 117 +++ .../analytics/model/domain/cef/Criticality.java | 31 + .../apod/analytics/model/domain/cef/Event.java | 63 ++ .../analytics/model/domain/cef/EventListener.java | 46 ++ .../analytics/model/domain/cef/EventSeverity.java | 36 + .../domain/cef/MeasurementsForVfScalingFields.java | 57 ++ .../model/domain/cef/PerformanceCounter.java | 65 ++ .../apod/analytics/model/domain/cef/Priority.java | 32 + .../domain/cef/ThresholdCrossingAlertFields.java | 161 ++++ .../analytics/model/domain/cef/VNicUsageArray.java | 79 ++ .../analytics/model/domain/policy/PolicyModel.java | 33 + .../domain/policy/tca/BaseTCAPolicyModel.java | 37 + .../model/domain/policy/tca/Direction.java | 56 ++ .../policy/tca/MetricsPerFunctionalRole.java | 81 ++ .../model/domain/policy/tca/TCAPolicy.java | 59 ++ .../model/domain/policy/tca/TCAPolicyModel.java | 35 + .../model/domain/policy/tca/Threshold.java | 86 +++ .../apod/analytics/model/facade/FacadeModel.java | 33 + .../dcae/apod/analytics/model/facade/tca/AAI.java | 38 + .../analytics/model/facade/tca/TCAFacadeModel.java | 31 + .../analytics/model/facade/tca/TCAVESResponse.java | 49 ++ .../model/util/AnalyticsModelIOUtils.java | 146 ++++ .../model/util/AnalyticsModelJsonUtils.java | 104 +++ .../json/AnalyticsModelObjectMapperSupplier.java | 112 +++ .../model/util/json/CommonEventFormatModule.java | 84 +++ .../model/util/json/TCAFacadeModelModule.java | 49 ++ .../analytics/model/util/json/TCAPolicyModule.java | 61 ++ .../mixin/BaseDynamicPropertiesProviderMixin.java | 45 ++ .../analytics/model/util/json/mixin/JsonMixin.java | 31 + .../util/json/mixin/cef/AlertActionMixin.java | 30 + .../model/util/json/mixin/cef/AlertTypeMixin.java | 61 ++ .../util/json/mixin/cef/BaseCEFModelMixin.java | 33 + .../json/mixin/cef/CommonEventHeaderMixin.java | 27 + .../util/json/mixin/cef/CriticalityMixin.java | 30 + .../util/json/mixin/cef/EventListenerMixin.java | 31 + .../model/util/json/mixin/cef/EventMixin.java | 31 + .../util/json/mixin/cef/EventSeverityMixin.java | 30 + .../cef/MeasurementsForVfScalingFieldsMixin.java | 39 + .../json/mixin/cef/PerformanceCounterMixin.java | 29 + .../model/util/json/mixin/cef/PriorityMixin.java | 30 + .../cef/ThresholdCrossingAlertFieldsMixin.java | 29 + .../util/json/mixin/cef/VNicUsageArrayMixin.java | 36 + .../model/util/json/mixin/facade/tca/AAIMixin.java | 54 ++ .../facade/tca/VESCEFMessageResponseMixin.java | 56 ++ .../mixin/policy/tca/BaseTCAPolicyModelMixin.java | 30 + .../util/json/mixin/policy/tca/DirectionMixin.java | 30 + .../policy/tca/MetricsPerFunctionalRoleMixin.java | 28 + .../util/json/mixin/policy/tca/TCAPolicyMixin.java | 28 + .../util/json/mixin/policy/tca/ThresholdMixin.java | 28 + .../model/BaseAnalyticsModelUnitTest.java | 148 ---- .../model/domain/cef/EventSeverityTest.java | 71 -- .../model/util/AnalyticsModelIOUtilsTest.java | 75 -- .../dcae/analytics/model/util/ConfigHolder.java | 33 - .../dcae/analytics/model/util/TestAppConfig.java | 40 - .../util/json/mixin/cef/AlertTypeMixinTest.java | 51 -- .../json/mixin/cef/EventListenerMixinTest.java | 88 --- .../mixin/facade/tca/TCAVESResponseMixinTest.java | 57 -- .../json/mixin/policy/tca/TCAPolicyMixinTest.java | 56 -- .../model/BaseAnalyticsModelUnitTest.java | 148 ++++ .../model/domain/cef/EventSeverityTest.java | 71 ++ .../model/util/AnalyticsModelIOUtilsTest.java | 75 ++ .../apod/analytics/model/util/ConfigHolder.java | 33 + .../apod/analytics/model/util/TestAppConfig.java | 40 + .../util/json/mixin/cef/AlertTypeMixinTest.java | 51 ++ .../json/mixin/cef/EventListenerMixinTest.java | 88 +++ .../mixin/facade/tca/TCAVESResponseMixinTest.java | 57 ++ .../json/mixin/policy/tca/TCAPolicyMixinTest.java | 56 ++ dcae-analytics-tca/pom.xml | 10 +- .../analytics/tca/TCAAnalyticsApplication.java | 105 --- .../analytics/tca/flow/TCAVESCollectorFlow.java | 69 -- .../tca/flowlet/TCAVESAlertsSinkFlowlet.java | 69 -- .../tca/flowlet/TCAVESMessageRouterFlowlet.java | 62 -- .../TCAVESThresholdViolationCalculatorFlowlet.java | 137 ---- .../tca/persistance/TCACalculatorMessageType.java | 43 -- .../tca/persistance/TCAMessageStatusEntity.java | 306 -------- .../tca/persistance/TCAMessageStatusPersister.java | 243 ------ .../tca/persistance/TCAVESAlertEntity.java | 77 -- .../tca/persistance/TCAVESAlertsPersister.java | 98 --- .../processor/AbstractTCAECEFPolicyProcessor.java | 61 -- .../tca/processor/TCACEFJsonProcessor.java | 98 --- .../tca/processor/TCACEFPolicyDomainFilter.java | 83 --- .../TCACEFPolicyFunctionalRoleFilter.java | 90 --- .../processor/TCACEFPolicyThresholdsProcessor.java | 135 ---- .../tca/processor/TCACEFProcessorContext.java | 103 --- .../dcae/analytics/tca/settings/TCAAppConfig.java | 96 --- .../analytics/tca/settings/TCAAppPreferences.java | 262 ------- .../tca/settings/TCAPolicyPreferences.java | 36 - .../AppPreferencesToPublisherConfigMapper.java | 82 -- .../AppPreferencesToSubscriberConfigMapper.java | 99 --- .../dcae/analytics/tca/utils/TCAUtils.java | 825 --------------------- .../tca/validator/TCAAppConfigValidator.java | 60 -- .../validator/TCAPolicyPreferencesValidator.java | 94 --- .../tca/validator/TCAPreferencesValidator.java | 63 -- .../tca/worker/TCADMaaPMRPublisherJob.java | 189 ----- .../tca/worker/TCADMaaPMRSubscriberJob.java | 175 ----- .../tca/worker/TCADMaaPMockSubscriberWorker.java | 139 ---- .../tca/worker/TCADMaaPPublisherWorker.java | 230 ------ .../tca/worker/TCADMaaPSubscriberWorker.java | 226 ------ .../analytics/tca/TCAAnalyticsApplication.java | 105 +++ .../analytics/tca/flow/TCAVESCollectorFlow.java | 69 ++ .../tca/flowlet/TCAVESAlertsSinkFlowlet.java | 69 ++ .../tca/flowlet/TCAVESMessageRouterFlowlet.java | 62 ++ .../TCAVESThresholdViolationCalculatorFlowlet.java | 137 ++++ .../tca/persistance/TCACalculatorMessageType.java | 43 ++ .../tca/persistance/TCAMessageStatusEntity.java | 306 ++++++++ .../tca/persistance/TCAMessageStatusPersister.java | 243 ++++++ .../tca/persistance/TCAVESAlertEntity.java | 77 ++ .../tca/persistance/TCAVESAlertsPersister.java | 98 +++ .../processor/AbstractTCAECEFPolicyProcessor.java | 61 ++ .../tca/processor/TCACEFJsonProcessor.java | 98 +++ .../tca/processor/TCACEFPolicyDomainFilter.java | 83 +++ .../TCACEFPolicyFunctionalRoleFilter.java | 90 +++ .../processor/TCACEFPolicyThresholdsProcessor.java | 135 ++++ .../tca/processor/TCACEFProcessorContext.java | 103 +++ .../apod/analytics/tca/settings/TCAAppConfig.java | 96 +++ .../analytics/tca/settings/TCAAppPreferences.java | 262 +++++++ .../tca/settings/TCAPolicyPreferences.java | 36 + .../AppPreferencesToPublisherConfigMapper.java | 82 ++ .../AppPreferencesToSubscriberConfigMapper.java | 99 +++ .../dcae/apod/analytics/tca/utils/TCAUtils.java | 825 +++++++++++++++++++++ .../tca/validator/TCAAppConfigValidator.java | 60 ++ .../validator/TCAPolicyPreferencesValidator.java | 94 +++ .../tca/validator/TCAPreferencesValidator.java | 63 ++ .../tca/worker/TCADMaaPMRPublisherJob.java | 189 +++++ .../tca/worker/TCADMaaPMRSubscriberJob.java | 175 +++++ .../tca/worker/TCADMaaPMockSubscriberWorker.java | 139 ++++ .../tca/worker/TCADMaaPPublisherWorker.java | 230 ++++++ .../tca/worker/TCADMaaPSubscriberWorker.java | 226 ++++++ .../dcae/analytics/tca/BaseAnalyticsTCAIT.java | 141 ---- .../analytics/tca/BaseAnalyticsTCAUnitTest.java | 220 ------ .../analytics/tca/it/TCAnalyticsAppConfigIT.java | 53 -- .../tca/processor/TCACEFJsonProcessorTest.java | 117 --- .../TCACEFPolicyThresholdsProcessorTest.java | 77 -- .../tca/processor/TCACEFProcessorContextTest.java | 38 - .../analytics/tca/settings/TCATestAppConfig.java | 38 - .../tca/settings/TCATestAppConfigHolder.java | 40 - .../tca/settings/TCATestAppPreferences.java | 136 ---- .../AppPreferencesToPublisherConfigMapperTest.java | 58 -- ...AppPreferencesToSubscriberConfigMapperTest.java | 59 -- .../dcae/analytics/tca/utils/TCAUtilsTest.java | 357 --------- .../tca/worker/TCADMaaPMRSubscriberJobTest.java | 80 -- .../apod/analytics/tca/BaseAnalyticsTCAIT.java | 141 ++++ .../analytics/tca/BaseAnalyticsTCAUnitTest.java | 220 ++++++ .../analytics/tca/it/TCAnalyticsAppConfigIT.java | 53 ++ .../tca/processor/TCACEFJsonProcessorTest.java | 117 +++ .../TCACEFPolicyThresholdsProcessorTest.java | 77 ++ .../tca/processor/TCACEFProcessorContextTest.java | 38 + .../analytics/tca/settings/TCATestAppConfig.java | 38 + .../tca/settings/TCATestAppConfigHolder.java | 40 + .../tca/settings/TCATestAppPreferences.java | 136 ++++ .../AppPreferencesToPublisherConfigMapperTest.java | 58 ++ ...AppPreferencesToSubscriberConfigMapperTest.java | 59 ++ .../apod/analytics/tca/utils/TCAUtilsTest.java | 357 +++++++++ .../tca/worker/TCADMaaPMRSubscriberJobTest.java | 80 ++ dcae-analytics-test/pom.xml | 2 +- .../test/BaseDCAEAnalyticsCommonTest.java | 216 ------ .../dcae/analytics/test/BaseDCAEAnalyticsIT.java | 29 - .../analytics/test/BaseDCAEAnalyticsUnitTest.java | 31 - .../analytics/test/annotation/GuiceModules.java | 45 -- .../analytics/test/runner/GuiceJUnitRunner.java | 102 --- .../test/BaseDCAEAnalyticsCommonTest.java | 216 ++++++ .../apod/analytics/test/BaseDCAEAnalyticsIT.java | 29 + .../analytics/test/BaseDCAEAnalyticsUnitTest.java | 31 + .../analytics/test/annotation/GuiceModules.java | 45 ++ .../analytics/test/runner/GuiceJUnitRunner.java | 102 +++ findbugs-exclude.xml | 6 +- pom.xml | 20 +- 377 files changed, 16205 insertions(+), 15981 deletions(-) delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/AnalyticsConstants.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPComponentsConstants.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPMetricsConstants.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/DCAEAnalyticsPreferences.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppConfig.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppPreferences.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppSettings.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPBaseAppConfig.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/validation/CDAPAppSettingsValidator.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/CDAPSettingsException.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/DCAEAnalyticsRuntimeException.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/MessageProcessingException.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractMessageProcessor.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractProcessorContext.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessor.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericProcessorInfo.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/MessageProcessor.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessingState.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorContext.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorInfo.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/HTTPUtils.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/MessageProcessorUtils.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/PersistenceUtils.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/ValidationUtils.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/DCAEValidator.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/GenericValidationResponse.java delete mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/ValidationResponse.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/AnalyticsConstants.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPComponentsConstants.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPMetricsConstants.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/DCAEAnalyticsPreferences.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppConfig.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppPreferences.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppSettings.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPBaseAppConfig.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/validation/CDAPAppSettingsValidator.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/CDAPSettingsException.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/DCAEAnalyticsRuntimeException.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/MessageProcessingException.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessor.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContext.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessor.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfo.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/MessageProcessor.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessingState.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorContext.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorInfo.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtils.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtils.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtils.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/ValidationUtils.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/DCAEValidator.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponse.java create mode 100644 dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/ValidationResponse.java delete mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/BaseAnalyticsCommonUnitTest.java delete mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessorTest.java delete mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestEarlyTerminatingProcessor.java delete mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor1.java delete mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor2.java delete mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestProcessorContext.java create mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java create mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java create mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java create mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java create mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java create mode 100644 dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactory.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRConfig.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRResponse.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPModule.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponent.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/DMaaPMRComponent.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisher.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java delete mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactory.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRConfig.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRResponse.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPModule.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/DMaaPMRComponent.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisher.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java create mode 100644 dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactoryTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRPublisherImplIT.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPTestModule.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponentTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java delete mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactoryTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRPublisherImplIT.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPTestModule.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponentTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java create mode 100644 dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/BaseDynamicPropertiesProvider.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DCAEAnalyticsModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DynamicPropertiesProvider.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertAction.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertType.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/BaseCEFModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CEFModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CommonEventHeader.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Criticality.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Event.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventListener.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventSeverity.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/MeasurementsForVfScalingFields.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/PerformanceCounter.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Priority.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/ThresholdCrossingAlertFields.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/VNicUsageArray.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/PolicyModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/BaseTCAPolicyModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Direction.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/MetricsPerFunctionalRole.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicy.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicyModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Threshold.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/FacadeModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/AAI.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAFacadeModel.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAVESResponse.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelIOUtils.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelJsonUtils.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/AnalyticsModelObjectMapperSupplier.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/CommonEventFormatModule.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/TCAFacadeModelModule.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/TCAPolicyModule.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/BaseDynamicPropertiesProviderMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/JsonMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/AlertActionMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/BaseCEFModelMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/CommonEventHeaderMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/CriticalityMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/EventListenerMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/EventMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/EventSeverityMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/MeasurementsForVfScalingFieldsMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/PerformanceCounterMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/PriorityMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/ThresholdCrossingAlertFieldsMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/VNicUsageArrayMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/facade/tca/AAIMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/facade/tca/VESCEFMessageResponseMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/policy/tca/BaseTCAPolicyModelMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/policy/tca/DirectionMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/policy/tca/MetricsPerFunctionalRoleMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/policy/tca/TCAPolicyMixin.java delete mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/BaseDynamicPropertiesProvider.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/DCAEAnalyticsModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/DynamicPropertiesProvider.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/AlertAction.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/AlertType.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/BaseCEFModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/CEFModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/CommonEventHeader.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/Criticality.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/Event.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/EventListener.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/EventSeverity.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/MeasurementsForVfScalingFields.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/PerformanceCounter.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/Priority.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/ThresholdCrossingAlertFields.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/cef/VNicUsageArray.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/PolicyModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/BaseTCAPolicyModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Direction.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/MetricsPerFunctionalRole.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/TCAPolicy.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/TCAPolicyModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/domain/policy/tca/Threshold.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/facade/FacadeModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/facade/tca/AAI.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/facade/tca/TCAFacadeModel.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/facade/tca/TCAVESResponse.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/AnalyticsModelIOUtils.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/AnalyticsModelJsonUtils.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/AnalyticsModelObjectMapperSupplier.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/CommonEventFormatModule.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/TCAFacadeModelModule.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/TCAPolicyModule.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/BaseDynamicPropertiesProviderMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/JsonMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/AlertActionMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/AlertTypeMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/BaseCEFModelMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/CommonEventHeaderMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/CriticalityMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/EventListenerMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/EventMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/EventSeverityMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/MeasurementsForVfScalingFieldsMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/PerformanceCounterMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/PriorityMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/ThresholdCrossingAlertFieldsMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/VNicUsageArrayMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/facade/tca/AAIMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/facade/tca/VESCEFMessageResponseMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/BaseTCAPolicyModelMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/DirectionMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/MetricsPerFunctionalRoleMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/TCAPolicyMixin.java create mode 100644 dcae-analytics-model/src/main/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/ThresholdMixin.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/BaseAnalyticsModelUnitTest.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/domain/cef/EventSeverityTest.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelIOUtilsTest.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/ConfigHolder.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/TestAppConfig.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/json/mixin/cef/EventListenerMixinTest.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/json/mixin/facade/tca/TCAVESResponseMixinTest.java delete mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/analytics/model/util/json/mixin/policy/tca/TCAPolicyMixinTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/BaseAnalyticsModelUnitTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/domain/cef/EventSeverityTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/AnalyticsModelIOUtilsTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/ConfigHolder.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/TestAppConfig.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/cef/EventListenerMixinTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/facade/tca/TCAVESResponseMixinTest.java create mode 100644 dcae-analytics-model/src/test/java/org/openecomp/dcae/apod/analytics/model/util/json/mixin/policy/tca/TCAPolicyMixinTest.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/TCAAnalyticsApplication.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/flow/TCAVESCollectorFlow.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/flowlet/TCAVESAlertsSinkFlowlet.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/flowlet/TCAVESMessageRouterFlowlet.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/flowlet/TCAVESThresholdViolationCalculatorFlowlet.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/persistance/TCACalculatorMessageType.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/persistance/TCAMessageStatusEntity.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/persistance/TCAMessageStatusPersister.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/persistance/TCAVESAlertEntity.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/persistance/TCAVESAlertsPersister.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/processor/AbstractTCAECEFPolicyProcessor.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/processor/TCACEFJsonProcessor.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/processor/TCACEFPolicyDomainFilter.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/processor/TCACEFPolicyFunctionalRoleFilter.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/processor/TCACEFProcessorContext.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/settings/TCAAppConfig.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/settings/TCAAppPreferences.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/settings/TCAPolicyPreferences.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/utils/AppPreferencesToPublisherConfigMapper.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/utils/AppPreferencesToSubscriberConfigMapper.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/utils/TCAUtils.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/validator/TCAAppConfigValidator.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/validator/TCAPolicyPreferencesValidator.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/validator/TCAPreferencesValidator.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/worker/TCADMaaPMRPublisherJob.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/worker/TCADMaaPMRSubscriberJob.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/worker/TCADMaaPMockSubscriberWorker.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/worker/TCADMaaPPublisherWorker.java delete mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/analytics/tca/worker/TCADMaaPSubscriberWorker.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/TCAAnalyticsApplication.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/flow/TCAVESCollectorFlow.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/flowlet/TCAVESAlertsSinkFlowlet.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/flowlet/TCAVESMessageRouterFlowlet.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/flowlet/TCAVESThresholdViolationCalculatorFlowlet.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/persistance/TCACalculatorMessageType.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/persistance/TCAMessageStatusEntity.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/persistance/TCAMessageStatusPersister.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/persistance/TCAVESAlertEntity.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/persistance/TCAVESAlertsPersister.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/AbstractTCAECEFPolicyProcessor.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFJsonProcessor.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyDomainFilter.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyFunctionalRoleFilter.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessor.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFProcessorContext.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/settings/TCAAppConfig.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/settings/TCAAppPreferences.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/settings/TCAPolicyPreferences.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/AppPreferencesToPublisherConfigMapper.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/AppPreferencesToSubscriberConfigMapper.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtils.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/validator/TCAAppConfigValidator.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/validator/TCAPolicyPreferencesValidator.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/validator/TCAPreferencesValidator.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/worker/TCADMaaPMRPublisherJob.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/worker/TCADMaaPMRSubscriberJob.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/worker/TCADMaaPMockSubscriberWorker.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/worker/TCADMaaPPublisherWorker.java create mode 100644 dcae-analytics-tca/src/main/java/org/openecomp/dcae/apod/analytics/tca/worker/TCADMaaPSubscriberWorker.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/BaseAnalyticsTCAIT.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/BaseAnalyticsTCAUnitTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/it/TCAnalyticsAppConfigIT.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/processor/TCACEFJsonProcessorTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/processor/TCACEFPolicyThresholdsProcessorTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/processor/TCACEFProcessorContextTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/settings/TCATestAppConfig.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/settings/TCATestAppConfigHolder.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/settings/TCATestAppPreferences.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/utils/AppPreferencesToPublisherConfigMapperTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/utils/AppPreferencesToSubscriberConfigMapperTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/utils/TCAUtilsTest.java delete mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/analytics/tca/worker/TCADMaaPMRSubscriberJobTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/BaseAnalyticsTCAIT.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/BaseAnalyticsTCAUnitTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/it/TCAnalyticsAppConfigIT.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFJsonProcessorTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFPolicyThresholdsProcessorTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/processor/TCACEFProcessorContextTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/settings/TCATestAppConfig.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/settings/TCATestAppConfigHolder.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/settings/TCATestAppPreferences.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/AppPreferencesToPublisherConfigMapperTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/AppPreferencesToSubscriberConfigMapperTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/utils/TCAUtilsTest.java create mode 100644 dcae-analytics-tca/src/test/java/org/openecomp/dcae/apod/analytics/tca/worker/TCADMaaPMRSubscriberJobTest.java delete mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/analytics/test/BaseDCAEAnalyticsCommonTest.java delete mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/analytics/test/BaseDCAEAnalyticsIT.java delete mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/analytics/test/BaseDCAEAnalyticsUnitTest.java delete mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/analytics/test/annotation/GuiceModules.java delete mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/analytics/test/runner/GuiceJUnitRunner.java create mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/apod/analytics/test/BaseDCAEAnalyticsCommonTest.java create mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/apod/analytics/test/BaseDCAEAnalyticsIT.java create mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/apod/analytics/test/BaseDCAEAnalyticsUnitTest.java create mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/apod/analytics/test/annotation/GuiceModules.java create mode 100644 dcae-analytics-test/src/main/java/org/openecomp/dcae/apod/analytics/test/runner/GuiceJUnitRunner.java diff --git a/README.md b/README.md index 71d62ca..cee5f19 100644 --- a/README.md +++ b/README.md @@ -101,3 +101,10 @@ curl -vk --user ${OPENECOMP_NEXUS_USER}:${OPENECOMP_NEXUS_PASSWORD} --upload-fil SEND_TO=${OPENECOMP_NEXUS_RAW}"/org.openecomp.dcae/deb-snapshots/"${PACKAGE_GROUP_ID}"/"${OUTPUT_FILE_DATE_STAMPED} curl -vk --user ${OPENECOMP_NEXUS_USER}:${OPENECOMP_NEXUS_PASSWORD} --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO} ``` + +#### TCA Application Configuration + +TCA Application is setup to do batching of publisher alerts (defaults to 10) which means publisher will +flush the alerts to DMaaP Topic only when total 10 alerts are available. To disable publisher batching set +"publisherMaxBatchSize" CDAP runtime argument to 1. This will flush alert message to DMaaP MR topic +instantaneously and will disable publisher batching. diff --git a/cpd-exclude.properties b/cpd-exclude.properties index 52abdf9..e4fb771 100644 --- a/cpd-exclude.properties +++ b/cpd-exclude.properties @@ -22,5 +22,4 @@ # List comma separated fully qualified names of classes that can be excluded for CPD (COPY-PASTE-DETECTOR) # Builders for DMaaP MR Configs can have redundant code as they are used as temp place holders for building Immutable # Configs -org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig,org.openecomp.dcae.analytics.dmaap.domain.config -.DMaaPMRSubscriberConfig +org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig,org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig diff --git a/dcae-analytics-common/pom.xml b/dcae-analytics-common/pom.xml index 1c58693..7da767f 100644 --- a/dcae-analytics-common/pom.xml +++ b/dcae-analytics-common/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics 1.0-SNAPSHOT ../pom.xml @@ -49,7 +49,7 @@ - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics-model 1.0-SNAPSHOT @@ -108,7 +108,7 @@ - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics-test 1.0-SNAPSHOT test diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/AnalyticsConstants.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/AnalyticsConstants.java deleted file mode 100644 index 6c51069..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/AnalyticsConstants.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common; - -/** - * Contains static variable for all DCAE Components. - * - * @author Rajiv Singla. Creation Date: 10/21/2016. - */ -public abstract class AnalyticsConstants { - - - // =============== Common Constants for all DCAE Analytics Modules ==================== // - - - // =============== DMaaP Constants for all DCAE Analytics Modules ==================== // - - public static final String DMAAP_URI_PATH_PREFIX = "/events/"; - public static final String DMAAP_GROUP_PREFIX = "OpenDCAE-"; - - // ================== DMaaP MR Constants ============================== // - // Publisher Constants - public static final int DEFAULT_PUBLISHER_MAX_BATCH_SIZE = 100; - public static final int DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 100000; - public static final int PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE = 5; - public static final int PUBLISHER_DELAY_MS_ON_RETRIES_ON_CLOSE = 5000; - // Subscriber Constants - public static final int DEFAULT_SUBSCRIBER_TIMEOUT_MS = -1; - public static final int DEFAULT_SUBSCRIBER_MESSAGE_LIMIT = -1; - public static final String DEFAULT_SUBSCRIBER_GROUP_PREFIX = DMAAP_GROUP_PREFIX + "DMaaPSub-"; - public static final String SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME = "timeout"; - public static final String SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME = "limit"; - - - // ================== TCA Constants ============================== // - - // Default subscriber polling interval - public static final Integer TCA_DEFAULT_SUBSCRIBER_POLLING_INTERVAL_MS = 30000; - - // Default publisher polling interval - public static final Integer TCA_DEFAULT_PUBLISHER_POLLING_INTERVAL_MS = 30000; - - // Default publisher max batch queue size determines the minimum number of messages that need to be published in - // batch mode - public static final Integer TCA_DEFAULT_PUBLISHER_MAX_BATCH_QUEUE_SIZE = 10; - - // Default publisher max recovery queue size determines max number of messages can be cached in memory - // in case publisher is not responding - public static final Integer TCA_DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 100000; - - // Default interval during which TCA DMaaP Worker checks if scheduler is shut down - public static final Integer TCA_DEFAULT_WORKER_SHUTDOWN_CHECK_INTERVAL_MS = 10000; - - // ***** TCA Quartz Scheduler Settings ******// - - public static final String TCA_QUARTZ_SUBSCRIBER_PROPERTIES_FILE_NAME = "quartz-subscriber.properties"; - - public static final String TCA_QUARTZ_PUBLISHER_PROPERTIES_FILE_NAME = "quartz-publisher.properties"; - - // TCA Quartz Group Settings - public static final String TCA_QUARTZ_GROUP_NAME = "TCAQuartzGroup"; - // TCA Quartz Trigger Settings - public static final String TCA_DMAAP_SUBSCRIBER_QUARTZ_TRIGGER_NAME = "TCADMaaPSubscriberTrigger"; - public static final String TCA_DMAAP_PUBLISHER_QUARTZ_TRIGGER_NAME = "TCADMaaPPublisherTrigger"; - - // TCA Quartz DMaaP Subscriber Job Settings - public static final String TCA_DMAAP_SUBSCRIBER_QUARTZ_JOB_NAME = "TCADMaaPSubscriberJob"; - public static final String TCA_DMAAP_PUBLISHER_QUARTZ_JOB_NAME = "TCADMaaPPublisherJob"; - - // TCA Quartz Publisher and Subscriber Job Parameters - // Common Job parameters for both Publisher and Subscriber - public static final String WORKER_CONTEXT_VARIABLE_NAME = "WORKER_CONTEXT"; - public static final String DMAAP_METRICS_VARIABLE_NAME = "DMAAP_METRICS"; - // TCA Quartz DMaaP Subscriber Job Parameter Settings - public static final String CDAP_STREAM_VARIABLE_NAME = "CDAP_STREAM_NAME"; - public static final String DMAAP_SUBSCRIBER_VARIABLE_NAME = "DMAAP_SUBSCRIBER"; - // TCA Quartz DMaaP Publisher Job Parameter Settings - public static final String CDAP_ALERTS_TABLE_VARIABLE_NAME = "CDAP_TCA_ALERTS_TABLE_NAME"; - public static final String DMAAP_PUBLISHER_VARIABLE_NAME = "DMAAP_PUBLISHER"; - - // TCA VES Response Constants - public static final String TCA_VES_RESPONSE_TARGET_TYPE = "VNF"; - public static final String TCA_VES_RESPONSE_TARGET = "generic-vnf.vnf-id"; - public static final String TCA_VES_RESPONSE_FROM = "DCAE"; - public static final String TCA_VES_RESPONSE_CLOSED_LOOP_EVENT_STATUS = "ONSET"; - - // TCA VES Response Constants for vLoadBalancer - public static final String LOAD_BALANCER_FUNCTIONAL_ROLE = "vLoadBalancer"; - public static final String LOAD_BALANCER_TCA_VES_RESPONSE_TARGET_TYPE = "VM"; - public static final String LOAD_BALANCER_TCA_VES_RESPONSE_TARGET = "vserver.vserver-name"; - - // TCA VES Message Router Partition Key - public static final String TCA_VES_MESSAGE_ROUTER_PARTITION_KEY = "VESMessageHash"; - - /** - * Default Number of instances for Threshold violation calculator flowlet - */ - public static final Integer TCA_DEFAULT_THRESHOLD_CALCULATOR_FLOWLET_INSTANCES = 2; - - /** - * Default TTL for TCA VES Message status table which contain status of all messages processed by TCA - */ - public static final Integer TCA_DEFAULT_VES_MESSAGE_STATUS_TTL_TABLE = 60 * 60 * 24 * 10; // 10 Days - - /** - * Default TTL for TCA VES Alerts table which contains alerts that can be send to downstream systems - */ - public static final Integer TCA_DEFAULT_VES_ALERTS_TTL_TABLE = 60 * 60 * 24 * 20; // 20 Days - - - // TCA Policy Runtime Argument Paths - public static final String TCA_POLICY_DELIMITER = "."; - public static final String TCA_POLICY_DOMAIN_PATH = "domain"; - public static final String TCA_POLICY_METRICS_PER_FUNCTIONAL_ROLE_PATH = "configuration.metricsPerFunctionalRole"; - public static final String TCA_POLICY_THRESHOLDS_PATH_POSTFIX = "thresholds"; -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPComponentsConstants.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPComponentsConstants.java deleted file mode 100644 index 50aad3c..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPComponentsConstants.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common; - -/** - * Contains static constant variable names and values of all DCAE CDAP Components for - * e.g. app names, app descriptions, streams, datasets, flows, flowlets, workers, outputs etc. - * - *

- * A strict naming convention must be followed for variable names for CDAP Components names for proper - * identification of CDAP Component variable purpose and function. A custom configuration settings can be - * generated for app - * deployment purposes based on variable naming conventions. - * - * The variable names should have 4 parts separated by an underscore: - *

    - *
  • Name of the DCAE sub module (e.g. TCA) to which variable is applicable
  • - *
  • Information about variable name: - *
      - *
    • FIXED - if variable value is fixed and cannot be changed
    • - *
    • DEFAULT - if variable name is default name and can be changed by cdap settings file - * when application is created
    • - *
    - *
  • - *
  • Actual Descriptive name about the CDAP component (may contain underscrores)
  • - *
  • CDAP component type e.g STREAM, DATASET, APP, FLOW, FLOWLET, OUTPUT
  • - *
- * - *

e.g TCA_DEFAULT_DMAAP_INPUT_STREAM

- * - *

RegEx Format (DCAE MODULE NAME)_(FIXED|DEFAULT)_(VARIABLE NAME)_(CDAP COMPONENT TYPE)

- * - * @author Rajiv Singla. Creation Date: 10/24/2016. - */ -public abstract class CDAPComponentsConstants { - - // =============== Common Module Constants ==================== // - - /** - * Default DCAE App Name. It should be overriden by sub modules - */ - public static final String COMMON_DEFAULT_DCAE_CDAP_NAME_APP = "DCAE_ANALYTICS_GENERIC_APP"; - - /** - * Default DCAE App Description. It should be overriden by sub modules - */ - public static final String COMMON_DEFAULT_DCAE_CDAP_DESCRIPTION_APP = "DCAE ANALYTICS GENERIC APP DESCRIPTION"; - - // =============== TCA Module Constants ==================== // - - /** - * Default TCA application name if application name is not provided from startup configuration - */ - public static final String TCA_DEFAULT_NAME_APP = "dcae-tca"; - - /** - * Default TCA application description if not provided from startup configuration - */ - public static final String TCA_DEFAULT_DESCRIPTION_APP = "DCAE Analytics Threshold Crossing Alert Application"; - - /** - * Default TCA DMaaP Subscriber output stream name if not provided from startup configuration - */ - public static final String TCA_DEFAULT_SUBSCRIBER_OUTPUT_NAME_STREAM = "TCASubscriberOutputStream"; - - - /** - * Fixed TCA DMaaP Subscriber output stream description - */ - public static final String TCA_FIXED_SUBSCRIBER_OUTPUT_DESCRIPTION_STREAM = - "Stream which contains all message from VES Collector DMaaP MR topic"; - - - /** - * Fixed Name of TCA DMaaP Subscriber Worker - which will be fetching DMaaP Messages posting them to CDAP stream - */ - public static final String TCA_FIXED_DMAAP_SUBSCRIBER_WORKER = "TCADMaaPMRSubscriberWorker"; - - /** - * Fixed Description of TCA DMaaP Subscriber Worker - */ - public static final String TCA_FIXED_DMAAP_SUBSCRIBER_DESCRIPTION_WORKER = - "Fetches messages from DMaaP MR Topic at frequent intervals and writes them to a CDAP stream"; - - /** - * Fixed Name of TCA DMaaP Publisher Worker - which will be publishing messages to DMaaP MR - */ - public static final String TCA_FIXED_DMAAP_PUBLISHER_WORKER = "TCADMaaPMRPublisherWorker"; - - /** - * Fixed Description of TCA DMaaP Publisher Worker - */ - public static final String TCA_FIXED_DMAAP_PUBLISHER_DESCRIPTION_WORKER = - "Polls TCA Alerts Table at frequent intervals for new alerts and publishes them to DMaaP MR Topic"; - - /** - * Fixed name for TCA VES Collector Messages Processing Flow - */ - public static final String TCA_FIXED_VES_COLLECTOR_NAME_FLOW = "TCAVESCollectorFlow"; - - - /** - * Fixed description for TCA VES Collector Messages Processing Flow - */ - public static final String TCA_FIXED_VES_COLLECTOR_DESCRIPTION_FLOW = "Flow performs TCA on VES Collector Messages"; - - - /** - * Fixed Name for TCA VES Message Router Flowlet - */ - public static final String TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET = "TCAVESMessageRouterFlowlet"; - - /** - * Fixed Description for TCA VES Message Router Flowlet - */ - public static final String TCA_FIXED_VES_MESSAGE_ROUTER_DESCRIPTION_FLOWLET = - "Routes message received from TCA VES Collector to TCA Threshold Calculator Flowlet instances"; - - /** - * Fixed TCA VES Message Router Flowlet Output - */ - public static final String TCA_FIXED_VES_MESSAGE_ROUTER_OUTPUT = "TCAVESMessageRouterFlowlet"; - - /** - * Fixed Name for TCA VES Message Policy Violated Threshold Calculator Flowlet - */ - public static final String TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_NAME_FLOWLET = - "TCAVESThresholdViolationCalculatorFlowlet"; - - /** - * Fixed Description for TCA VES Message Policy Violated Threshold Calculator Flowlet - */ - public static final String TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_DESCRIPTION_FLOWLET = - "Applies TCA Policy Thresholds to VES Message and determined if any message violated TCA Policy thresholds"; - - /** - * Fixed Name for TCA VES Message Policy Violated Threshold Calculator Output - */ - public static final String TCA_FIXED_VES_TCA_CALCULATOR_NAME_OUTPUT = "TCAThresholdViolationCalculatorOutput"; - - - /** - * Fixed Name for TCA VES Alerts Sink Flowlet - */ - public static final String TCA_FIXED_VES_ALERTS_SINK_NAME_FLOWLET = "TCAVESAlertsSinkFlowlet"; - - /** - * Fixed Description for TCA VES Alerts Sink Flowlet - */ - public static final String TCA_FIXED_VES_ALERTS_SINK_DESCRIPTION_FLOWLET = - "Saves messages which violated TCA Policy in a data set"; - - - /** - * Default Name for TCA VES Message status table which contain status of all messages processed by TCA - */ - public static final String TCA_DEFAULT_VES_MESSAGE_STATUS_NAME_TABLE = "TCAVESMessageStatusTable"; - - - /** - * Fixed Description for TCA VES Message status table which contain status of all messages processed by TCA - */ - public static final String TCA_FIXED_VES_MESSAGE_STATUS_DESCRIPTION_TABLE = - "Store processing information about all incoming TCA VES Messages"; - - /** - * Default Name for TCA VES Alerts table which contains alerts that can be send to downstream systems - */ - public static final String TCA_DEFAULT_VES_ALERTS_NAME_TABLE = "TCAVESAlertsTable"; - - /** - * Fixed Description for TCA VES Alerts table which contains alerts that can be send to downstream systems - */ - public static final String TCA_DEFAULT_VES_ALERTS_DESCRIPTION_TABLE = - "Stores alert messages that need to be DMaaP"; - - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPMetricsConstants.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPMetricsConstants.java deleted file mode 100644 index 12df643..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/CDAPMetricsConstants.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common; - -/** - * Contains all metrics names used for DCAE CDAP modules - * - *

- * Format should be (ModuleName)_(Description of metrics)_METRIC e.g. TCA_WORKER_FAILED_ATTEMPTS_METRIC - *

- * - * @author Rajiv Singla. Creation Date: 10/25/2016. - */ -public abstract class CDAPMetricsConstants { - - /** - * Metric captures count of all responses received from DMaaP MR Subscriber Topic - */ - public static final String TCA_SUBSCRIBER_ALL_RESPONSES_COUNT_METRIC = "tca.subscriber.fetch.all_responses"; - - /** - * Metric captures count of responses from DMaaP MR Subscriber Topic which does not have 200 HTTP Response code. - * This can be due to DMaaP topic being down or any internal server errors etc. - */ - public static final String TCA_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC = "tca.subscriber.fetch.unsuccessful"; - - /** - * Metric that counts the number of successful (200 HTTP Response Code) calls to DMaaP which did not had empty - * messages - */ - public static final String TCA_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC = "tca.subscriber.fetch.no_message"; - - /** - * Metric to count total number of VES Collector message processed by tca subscriber - */ - public static final String TCA_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC = "tca.subscriber.message.count"; - - - /** - * Metric to record time taken in ms by subscriber in its most recent call to fetch DMaaP MR messages - */ - public static final String TCA_SUBSCRIBER_RESPONSE_TIME_MS_METRIC = "tca.subscriber.fetch.response_time"; - - /** - * Metric captures the count of number of times DMaaP MR Subscriber was unable to write to DMaaP Stream due - * some CDAP error while writing to stream. This should ideally never happen assuming we have enough space - * on CDAP machine and CDAP process is functioning normally - */ - public static final String TCA_SUBSCRIBER_FAILURE_TO_WRITE_TO_STREAM_METRIC = "tca.subscriber.stream.writing.error"; - - - /** - * Metric captures number of VES messages that are not applicable as per TCA Policy - */ - public static final String TCA_VES_INAPPLICABLE_MESSAGES_METRIC = "tca.ves.calculator.inapplicable"; - - /** - * Metric captures number of VES messages that are applicable as per TCA Policy but don't violate any thresholds - */ - public static final String TCA_VES_COMPLIANT_MESSAGES_METRIC = "tca.ves.calculator.compliant"; - - /** - * Metrics captures number of VES messages that are applicable as per TCA Policy and does violate thresholds and - * will likely cause an alert - */ - public static final String TCA_VES_NON_COMPLIANT_MESSAGES_METRIC = "tca.ves.calculator.non_compliant"; - - - /** - * Metric that counts the number of publisher look ups in alerts table which resulted in 0 new alerts - */ - public static final String TCA_PUBLISHER_NO_NEW_ALERTS_LOOKUP_METRIC = "tca.publisher.lookup.no_message"; - - /** - * Metric that counts the number of new alerts found by the publisher in alerts table - */ - public static final String TCA_PUBLISHER_NEW_ALERTS_METRIC = "tca.publisher.lookup.new_messages"; - - /** - * Metric that counts the number of alerts deleted by publisher in alerts table - */ - public static final String TCA_PUBLISHER_DELETED_ALERTS_METRIC = "tca.publisher.deleted.alerts"; - - /** - * Metric that counts the number of publisher calls to DMaaP which resulted in successful response code - */ - public static final String TCA_PUBLISHER_SUCCESSFUL_DMAAP_RESPONSE_METRIC = "tca.publisher.publish.successful"; - - /** - * Metric that counts the number of publisher calls to DMaaP which resulted in unsuccessful response code - */ - public static final String TCA_PUBLISHER_UNSUCCESSFUL_DMAAP_RESPONSE_METRIC = "tca.publisher.publish.unsuccessful"; - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/DCAEAnalyticsPreferences.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/DCAEAnalyticsPreferences.java deleted file mode 100644 index dc345f4..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/DCAEAnalyticsPreferences.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common; - -/** - * A Marker Interface for all DCAE Analytics Preferences - * - * @author Rajiv Singla. Creation Date: 10/26/2016. - */ -public interface DCAEAnalyticsPreferences { -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppConfig.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppConfig.java deleted file mode 100644 index 3fc6f22..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.cdap.settings; - -/** - *

- * Minimum Contract for all CDAP App Configs - *

- * - * @author Rajiv Singla. Creation Date: 11/2/2016. - */ -public interface CDAPAppConfig extends CDAPAppSettings { - - /** - * CDAP Application Name - * - * @return cdap app name - */ - String getAppName(); - - - /** - * CDAP Application Description - * - * @return cdap app description - */ - String getAppDescription(); - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppPreferences.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppPreferences.java deleted file mode 100644 index 52ec1af..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppPreferences.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.cdap.settings; - -/** - *

- * Marker Interface for all CDAP Preferences - *

- * - * @author Rajiv Singla. Creation Date: 11/2/2016. - */ -public interface CDAPAppPreferences extends CDAPAppSettings { -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppSettings.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppSettings.java deleted file mode 100644 index d59e6f4..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPAppSettings.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.cdap.settings; - -import java.io.Serializable; - -/** - *

- * A marker interface for all CDAP Related App Settings. - * App Settings can either be preferences, cdap app settings etc. - *

- * - * - * @author Rajiv Singla. Creation Date: 11/2/2016. - */ -public interface CDAPAppSettings extends Serializable { -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPBaseAppConfig.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPBaseAppConfig.java deleted file mode 100644 index 1360b20..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/settings/CDAPBaseAppConfig.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.cdap.settings; - -import co.cask.cdap.api.Config; -import org.openecomp.dcae.analytics.common.CDAPComponentsConstants; - -/** - * Base class for all DACE Analytics Application Configurations - * - * @author Rajiv Singla. Creation Date: 10/4/2016. - */ -public abstract class CDAPBaseAppConfig extends Config implements CDAPAppConfig { - - - /** - * DCAE Analytics App Name - */ - protected String appName = CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_NAME_APP; - - /** - * DCAE Analytics App Description - */ - protected String appDescription = CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_DESCRIPTION_APP; - - - /** - * Returns DCAE Analytics CDAP Application name - * - * @return CDAP application name - */ - public String getAppName() { - return appName; - } - - /** - * Returns DCAE Analytics CDAP Application descrption - * - * @return CDAP application description - */ - public String getAppDescription() { - return appDescription; - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/validation/CDAPAppSettingsValidator.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/validation/CDAPAppSettingsValidator.java deleted file mode 100644 index df00eff..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/cdap/validation/CDAPAppSettingsValidator.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.cdap.validation; - -import org.openecomp.dcae.analytics.common.cdap.settings.CDAPAppSettings; -import org.openecomp.dcae.analytics.common.validation.DCAEValidator; -import org.openecomp.dcae.analytics.common.validation.ValidationResponse; - -/** - *

- * Validates CDAP Application Settings (AppConfig, Preferences etc) - *

- * - * @param {@link CDAPAppSettings} DCAE Analytics App Settings (e.g. AppConfig, Preferences) - * @param {@link ValidationResponse} Validator response implementations - * - * @author Rajiv Singla. Creation Date: 11/2/2016. - */ -public interface CDAPAppSettingsValidator> - extends DCAEValidator { - - /** - * Validates DCAE Analytics App Settings and return Validation response which can be - * checked for any app setting issues - * - * @param appSettings DCAE CDAP Application Settings (e.g. AppConfig, Preferences etc.) - * @return validation response - */ - R validateAppSettings(T appSettings); - - -} - - diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/CDAPSettingsException.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/CDAPSettingsException.java deleted file mode 100644 index f6859e2..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/CDAPSettingsException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.exception; - -import org.slf4j.Logger; - -/** - * Runtime exception which signals that DCAE CDAP App settings (e.g. app config, preferences) validation failed - * - * @author Rajiv Singla. Creation Date: 10/24/2016. - */ -public class CDAPSettingsException extends DCAEAnalyticsRuntimeException { - - /** - * @param message - Error Message for Exception - * @param cause - Actual Exception which caused {@link DCAEAnalyticsRuntimeException} - */ - public CDAPSettingsException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Creates and logs the DCAE App Config Exception to given logger - * - * @param message - Error Message for Exception and logging - * @param logger - Logger used for logging exception - * @param cause - Actual exception which caused - */ - public CDAPSettingsException(String message, Logger logger, Throwable cause) { - super(message, logger, cause); - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/DCAEAnalyticsRuntimeException.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/DCAEAnalyticsRuntimeException.java deleted file mode 100644 index cc00e33..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/DCAEAnalyticsRuntimeException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.exception; - -import org.slf4j.Logger; - -/** - * Runtime Exception for DCAE Analytics Exceptions. All DCAE Analytics - * runtime Exceptions must be wrapped inside this exception - *

- * @author Rajiv Singla. Creation Date: 10/5/2016. - */ -public class DCAEAnalyticsRuntimeException extends RuntimeException { - - - /** - * @param message - Error Message for Exception - * @param cause - Actual Exception which caused {@link DCAEAnalyticsRuntimeException} - */ - public DCAEAnalyticsRuntimeException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Creates and logs the DCAE Runtime Exception to given logger - * - * @param message - Error Message for Exception and logging - * @param logger - Logger used for logging exception - * @param cause - Actual exception which caused {@link DCAEAnalyticsRuntimeException} - */ - public DCAEAnalyticsRuntimeException(String message, Logger logger, Throwable cause) { - super(message, cause); - logger.error(message); - } - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/MessageProcessingException.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/MessageProcessingException.java deleted file mode 100644 index b40f604..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/exception/MessageProcessingException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.exception; - -import org.openecomp.dcae.analytics.common.service.processor.MessageProcessor; -import org.slf4j.Logger; - -/** - * Runtime Exception caused due to {@link MessageProcessor} failure while processing a message. - * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public class MessageProcessingException extends DCAEAnalyticsRuntimeException { - - /** - * @param message - Error Message for Exception - * @param cause - Actual Exception which caused {@link DCAEAnalyticsRuntimeException} - */ - public MessageProcessingException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Creates and logs the DCAE Runtime Exception to given logger - * - * @param message - Error Message for Exception and logging - * @param logger - Logger used for logging exception - * @param cause - Actual exception which caused {@link DCAEAnalyticsRuntimeException} - */ - public MessageProcessingException(String message, Logger logger, Throwable cause) { - super(message, logger, cause); - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractMessageProcessor.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractMessageProcessor.java deleted file mode 100644 index e5b9afc..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractMessageProcessor.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import com.google.common.base.Optional; -import org.openecomp.dcae.analytics.common.exception.MessageProcessingException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; - -import static java.lang.String.format; - -/** - * An abstract Message Processor which can be extended by {@link MessageProcessor} implementations - * to get default behavior for Message Processors - * - * @param

Processor Context sub classes - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public abstract class AbstractMessageProcessor

implements MessageProcessor

{ - - private static final Logger LOG = LoggerFactory.getLogger(AbstractMessageProcessor.class); - - /** - * By Default there is no processing message - */ - private String processingMessage = null; - - /** - * By Default Processing State is set to not required - subclasses must - * set processing state to {@link ProcessingState#PROCESSING_FINISHED_SUCCESSFULLY} on successful processing - * or {@link ProcessingState#PROCESSING_TERMINATED_EARLY} if processing fails - */ - protected ProcessingState processingState = ProcessingState.PROCESSING_NOT_REQUIRED; - - /** - * Sub classes must provide a description of a processor - * - * @return description of processor - * - */ - public abstract String getProcessorDescription(); - - - /** - * Sub classes must provide implementation to process Message - * - * @param processorContext incoming {@link ProcessorContext} - * @return outgoing {@link ProcessorContext} - */ - public abstract P processMessage(P processorContext); - - @Override - public ProcessorInfo getProcessorInfo() { - // by default the class of the Processor is assigned as Processor Name - final String processorClassName = getClass().getSimpleName(); - return new GenericProcessorInfo(processorClassName, getProcessorDescription()); - } - - @Override - public P preProcessor(P processorContext) { - LOG.debug("Processing Started for Processor: {}", getProcessorInfo().getProcessorName()); - // by default check to see if continue processing Flag is not false - final boolean okToContinue = processorContext.canProcessingContinue(); - if (!okToContinue) { - final String errorMessage = - format("Processor: %s. Processing Context flag okToContinue is false. Unable to proceed...", - getProcessorInfo().getProcessorName()); - throw new MessageProcessingException(errorMessage, LOG, new IllegalStateException(errorMessage)); - } - processingState = ProcessingState.PROCESSING_STARTED; - return processorContext; - } - - @Override - public ProcessingState getProcessingState() { - return processingState; - } - - @Override - public Optional getProcessingMessage() { - return Optional.fromNullable(processingMessage); - } - - @Override - public P postProcessor(P processorContext) { - // Default implementation updates the post processing flag if processing did not - // completed successfully - if (processingState != ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY) { - LOG.debug("Processor: {}, Update Process Context State to stop Processing.", - getProcessorInfo().getProcessorName()); - processorContext.setProcessingContinueFlag(false); - } - // attaches itself to message processor context - processorContext.getMessageProcessors().add(this); - LOG.debug("Processing Completed for Processor: {}", getProcessorInfo()); - return processorContext; - } - - - @Override - public final P apply(@Nonnull P processorContext) { - final P preProcessedProcessorContext = preProcessor(processorContext); - final P processedProcessorContext = processMessage(preProcessedProcessorContext); - return postProcessor(processedProcessorContext); - } - - - /** - * Helper method that updates processing state in case of early termination, logs the processing - * termination reason, updates Processor processing state as Terminated and sets it processing message - * - * @param terminatingMessage error Message - * @param processorContext message processor context - */ - protected void setTerminatingProcessingMessage(final String terminatingMessage, - final P processorContext) { - - final String message = processorContext.getMessage(); - this.processingState = ProcessingState.PROCESSING_TERMINATED_EARLY; - this.processingMessage = terminatingMessage; - LOG.debug("Processor: {}, Early Terminating Message: {}, Incoming Message: {}", - getProcessorInfo().getProcessorName(), terminatingMessage, message); - } - - /** - * Helper method that updates Processing state and logs completion message - * passed - * - * @param processorPassingMessage Processor passing message - * @param processorContext message processor context - */ - protected void setFinishedProcessingMessage(final String processorPassingMessage, P processorContext) { - final String message = processorContext.getMessage(); - processingState = ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY; - this.processingMessage = processorPassingMessage; - LOG.debug("Processor: {}, Successful Completion Message: {}, Incoming Message: {}", - getProcessorInfo().getProcessorName(), processorPassingMessage, message); - } - - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractProcessorContext.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractProcessorContext.java deleted file mode 100644 index 15145b5..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/AbstractProcessorContext.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import com.google.common.base.Objects; - -import java.util.LinkedList; -import java.util.List; - -/** - *

- * An abstract implementation for {@link ProcessorContext} which other DCAE Analytics Modules - * can extend to add module specific functionality - *

- * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public abstract class AbstractProcessorContext implements ProcessorContext { - - private final String message; - private List> messageProcessors; - private boolean canProcessingContinue; - - public AbstractProcessorContext(final String message, - boolean canProcessingContinue) { - this.message = message; - this.canProcessingContinue = canProcessingContinue; - this.messageProcessors = new LinkedList<>(); - } - - /** - * Returns JSON String of incoming CEF Message that needs to be processed - * - * @return incoming CEF message that needs to be processed - */ - @Override - public String getMessage() { - return message; - } - - /** - * Sets if it is ok to continue processing normally - * - * @return boolean which determines if it is ok to continue processing normally - */ - @Override - public boolean canProcessingContinue() { - return canProcessingContinue; - } - - - /** - * Set if it is ok to continue processing normally - * - * @param canProcessingContinue sets boolean which determines if it is ok to continue processing normally - */ - @Override - public void setProcessingContinueFlag(boolean canProcessingContinue) { - this.canProcessingContinue = canProcessingContinue; - } - - /** - * Provides List of message processors which were used in processing CEF message - * - * @return List of message processors which were used in processing CEF message - */ - @Override - public List> getMessageProcessors() { - return messageProcessors; - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("canProcessingContinue", canProcessingContinue) - .toString(); - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessor.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessor.java deleted file mode 100644 index b86d3ad..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessor.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import org.openecomp.dcae.analytics.common.utils.MessageProcessorUtils; - -import java.util.List; - -/** - *

- * A Generic Message Processor which passes the {@link ProcessorContext} from first to second - * {@link MessageProcessor} - *

- * - * @param

Processor Context sub classes - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public class GenericMessageChainProcessor

{ - - private final List> messageProcessors; - private final P initialProcessorContext; - - public GenericMessageChainProcessor(List> messageProcessors, - P initialProcessorContext) { - this.messageProcessors = messageProcessors; - this.initialProcessorContext = initialProcessorContext; - } - - public P processChain() { - - final MessageProcessorUtils.MessageProcessorFunction

messageProcessorFunction = - new MessageProcessorUtils.MessageProcessorFunction

() { - @Override - public > P apply(P context, M processor) { - return processor.apply(context); - } - }; - - return MessageProcessorUtils.computeMessageProcessorChain(messageProcessors, initialProcessorContext, - messageProcessorFunction); - - } - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericProcessorInfo.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericProcessorInfo.java deleted file mode 100644 index 665f787..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/GenericProcessorInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import javax.annotation.Nonnull; - -/** - * A Generic Implementation of {@link ProcessorInfo} - * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public class GenericProcessorInfo implements ProcessorInfo { - - private static final long serialVersionUID = -2840512323233649809L; - - private final String processorName; - private final String processorDescription; - - public GenericProcessorInfo(@Nonnull String processorName, @Nonnull String processorDescription) { - this.processorName = processorName; - this.processorDescription = processorDescription; - } - - public String getProcessorName() { - return processorName; - } - - public String getProcessorDescription() { - return processorDescription; - } - - - @Override - public String toString() { - return processorName; - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/MessageProcessor.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/MessageProcessor.java deleted file mode 100644 index 3c09da9..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/MessageProcessor.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import com.google.common.base.Function; -import com.google.common.base.Optional; - -import java.io.Serializable; - -/** - *

- * A message processor can be used to process incoming messages. - * It uses implementations of {@link ProcessorContext} as input and output - *

- * - * @param

Message Processor Context implementations - * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public interface MessageProcessor

extends Function, Serializable { - - /** - * Returns processor information - * - * @return processor Information - */ - ProcessorInfo getProcessorInfo(); - - - /** - * Does pre-processing of {@link ProcessorContext} e.g. validate input conditions and return - * pre processed context - * - * @param processorContext incoming Processor Context - * @return Pre processed Processor Context - */ - P preProcessor(P processorContext); - - - /** - * Return processing state of a processor - * - * @return Processing State - */ - ProcessingState getProcessingState(); - - - /** - * May return a message from a processor which indicates the reason for {@link ProcessingState} especially if - * there was some failure in processing - * - * @return processing Message - */ - Optional getProcessingMessage(); - - - /** - * Does post-processing of {@link ProcessorContext} - * - * @param processorContext incoming Processor Context - * @return processor Context after post processing is finished - */ - P postProcessor(P processorContext); - - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessingState.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessingState.java deleted file mode 100644 index c5090f7..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessingState.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -/** - *

- * Processing state of a {@link MessageProcessor} - *

- * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -public enum ProcessingState { - - PROCESSING_STARTED, - PROCESSING_FINISHED_SUCCESSFULLY, - PROCESSING_TERMINATED_EARLY, - PROCESSING_NOT_REQUIRED; - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorContext.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorContext.java deleted file mode 100644 index 74eabd7..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorContext.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import java.io.Serializable; -import java.util.List; - -/** - *

- * A Processor Context is used a an input and output to a {@link MessageProcessor} - *
- * DCAE Analytics sub projects should extend this interface and add specific fields - * required for input and output - *

- * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public interface ProcessorContext extends Serializable { - - /** - * Returns Processor Context message that will be processed by Chain of Processors - * - * @return message that need to be processed by processors - */ - String getMessage(); - - /** - * Processing Context flag which determines if Processing can continue in a processing - * chain - * - * @return true if ok to continue processing normally - */ - boolean canProcessingContinue(); - - - /** - * Sets new value for ProcessingContinue flag which will cause early termination of processing in chain if - * set to false - * - * @param canProcessingContinue set new value for canProcessing Continue flag - */ - void setProcessingContinueFlag(boolean canProcessingContinue); - - - /** - * Provides a List of previous processors which have completed processing - * - * @return list of previous processors - */ - List> getMessageProcessors(); - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorInfo.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorInfo.java deleted file mode 100644 index e657ed7..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/service/processor/ProcessorInfo.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import java.io.Serializable; - -/** - *

- * Contains Information about a processor. For e.g. Processor name, processor description etc - *

- * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public interface ProcessorInfo extends Serializable { - - /** - * Returns a name which should uniquely identify a particular {@link MessageProcessor} - * - * @return processor name - */ - String getProcessorName(); - - - /** - * Returns description of a {@link MessageProcessor} - * - * @return processor description - */ - String getProcessorDescription(); - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/HTTPUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/HTTPUtils.java deleted file mode 100644 index 4c36cb3..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/HTTPUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.utils; - -/** - * Contains common utils to check HTTP Related Utils - * - * @author Rajiv Singla. Creation Date: 11/2/2016. - */ -public abstract class HTTPUtils { - - /** - * HTTP Status code for successful HTTP call - */ - public static final Integer HTTP_SUCCESS_STATUS_CODE = 200; - - /** - * HTTP Response code when request has been accepted for processing, but the processing has not been completed - */ - public static final Integer HTTP_ACCEPTED_RESPONSE_CODE = 202; - - /** - * HTTP Response code when there is no content - */ - public static final Integer HTTP_NO_CONTENT_RESPONSE_CODE = 204; - - - public static final String JSON_APPLICATION_TYPE = "application/json"; - - /** - * Checks if HTTP Status code is less than or equal to 200 but less then 300 - * - * @param statusCode http status code - * @return true if response code between 200 and 300 - */ - public static boolean isSuccessfulResponseCode(Integer statusCode) { - return statusCode >= 200 && statusCode < 300; - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/MessageProcessorUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/MessageProcessorUtils.java deleted file mode 100644 index 10c8d7c..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/MessageProcessorUtils.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.utils; - -import org.openecomp.dcae.analytics.common.exception.MessageProcessingException; -import org.openecomp.dcae.analytics.common.service.processor.MessageProcessor; -import org.openecomp.dcae.analytics.common.service.processor.ProcessorContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Iterator; - - -/** - * Contains utility methods for {@link MessageProcessor} - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public abstract class MessageProcessorUtils { - - private static final Logger LOG = LoggerFactory.getLogger(MessageProcessorUtils.class); - - /** - * Provides an abstraction how to apply {@link ProcessorContext} to next {@link MessageProcessor} - * in the message processor chain - * - * @param

Sub classes of Processor Context - */ - public interface MessageProcessorFunction

{ - - /** - * Method which provides accumulated {@link ProcessorContext} from previous processors and a reference - * to next processor in the chain - * - * @param p accumulated {@link ProcessorContext} from previous processors - * @param m current {@link MessageProcessor} in the chain - * @param Message processor sub classes - * - * @return processing context after computing the current Message Processor - */ - > P apply(P p, M m); - } - - - /** - * Provides an abstraction to compute a chain of {@link MessageProcessor} - * - * @param messageProcessors An iterable containing one or more {@link MessageProcessor}s - * @param initialProcessorContext An initial processing Context - * @param messageProcessorFunction messageProcessor Function - * @param

Sub classes for Processor Context - * - * @return processing context which results after computing the whole chain - */ - public static

P computeMessageProcessorChain( - final Iterable> messageProcessors, - final P initialProcessorContext, - final MessageProcessorFunction

messageProcessorFunction) { - - // Get message processor iterator - final Iterator> processorIterator = messageProcessors.iterator(); - - // If no next message processor - return initial processor context - if (!processorIterator.hasNext()) { - return initialProcessorContext; - } - - // An accumulator for processor Context - P processorContextAccumulator = initialProcessorContext; - - while (processorIterator.hasNext()) { - - final MessageProcessor

nextProcessor = processorIterator.next(); - - // If Initial Processor Context is null - if (processorContextAccumulator == null) { - final String errorMessage = - String.format("Processor Context must not be null for Message Process: %s", - nextProcessor.getProcessorInfo().getProcessorName()); - throw new MessageProcessingException(errorMessage, LOG, new IllegalStateException(errorMessage)); - } - - - if (!processorContextAccumulator.canProcessingContinue()) { - LOG.debug("Triggering Early Termination, before Message Processor: {}, Incoming Message: {}", - nextProcessor.getProcessorInfo().getProcessorName(), processorContextAccumulator.getMessage()); - break; - } - processorContextAccumulator = messageProcessorFunction.apply(processorContextAccumulator, nextProcessor); - } - - return processorContextAccumulator; - } - - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/PersistenceUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/PersistenceUtils.java deleted file mode 100644 index e408171..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/PersistenceUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.utils; - -import java.util.Date; - -/** - * Contains Utility methods for creating persistence row keys etc. - * - * @author Rajiv Singla. Creation Date: 11/16/2016. - */ -public abstract class PersistenceUtils { - - - /** - * Name of the column which will contain Table Key - */ - public static final String TABLE_ROW_KEY_COLUMN_NAME = "key"; - - /** - * Delimited to be used when creating a row key with multiple fields - */ - public static final String ROW_KEY_DELIMITER = "-"; - - /** - * Creates a decreasing number using current timestamp. Handy when you want to keep records most recent records - * close to the top of column table like HBase - * - * @return decreasing number - */ - public static String getCurrentTimeReverseSubKey() { - final long timeReverseLong = Long.MAX_VALUE - new Date().getTime(); - return String.format("%025d", timeReverseLong); - } - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/ValidationUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/ValidationUtils.java deleted file mode 100644 index 694529f..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/utils/ValidationUtils.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.utils; - -import org.openecomp.dcae.analytics.common.cdap.settings.CDAPAppSettings; -import org.openecomp.dcae.analytics.common.cdap.validation.CDAPAppSettingsValidator; -import org.openecomp.dcae.analytics.common.exception.CDAPSettingsException; -import org.openecomp.dcae.analytics.common.validation.ValidationResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Contains utility methods to validate null checks, empty string etc - * - * @author Rajiv Singla. Creation Date: 10/24/2016. - */ -public abstract class ValidationUtils { - - private static final Logger LOG = LoggerFactory.getLogger(ValidationUtils.class); - - /** - * Checks if String is empty. For null string true is returned - * - * @param stringValue string value - * @return returns true is string is empty or null - */ - public static boolean isEmpty(final @Nullable String stringValue) { - return stringValue == null || stringValue.isEmpty() || stringValue.trim().isEmpty(); - } - - - /** - * Provides common functionality to Validates CDAP App Settings. Throws Runtime exception if validation fails - * - * @param appSettings app Settings e.g. App Config, App Preferences etc - * @param appSettingsValidator app Settings validator - * - * @param Settings type e.g. AppConfig or AppPreferences - * @param Validation Response type - * @param Validator Type - */ - public static , - V extends CDAPAppSettingsValidator> void validateSettings(final @Nonnull T appSettings, - final @Nonnull V appSettingsValidator) { - checkNotNull(appSettings, "App Settings must not be null"); - checkNotNull(appSettingsValidator, "App Settings validator must not be null"); - - final String appSettingsClassName = appSettings.getClass().getSimpleName(); - final String appSettingsClassValidator = appSettingsValidator.getClass().getSimpleName(); - - LOG.debug("Validating App Settings for: {}, with App Settings Validator: {} ", - appSettingsClassName, appSettingsClassValidator); - - final R validationResponse = appSettingsValidator.validateAppSettings(appSettings); - - // If setting validation fails throw an exception - if (validationResponse.hasErrors()) { - throw new CDAPSettingsException( - validationResponse.getAllErrorMessage(), LOG, new IllegalArgumentException()); - } - - LOG.debug("App Settings Validation Successful for app Settings: {} with validator: {}", appSettingsClassName, - appSettingsClassValidator); - } - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/DCAEValidator.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/DCAEValidator.java deleted file mode 100644 index 065411f..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/DCAEValidator.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.validation; - -/** - * Marker interface for all DCAE Validators - * - * @author Rajiv Singla. Creation Date: 10/24/2016. - */ -public interface DCAEValidator { -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/GenericValidationResponse.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/GenericValidationResponse.java deleted file mode 100644 index 7015ffe..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/GenericValidationResponse.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.validation; - -import com.google.common.base.Joiner; -import com.google.common.base.Objects; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; - -/** - * A generic implementation of Validation Response - * - * @param Validation Entity Type - * - * @author Rajiv Singla. Creation Date: 10/24/2016. - */ -public class GenericValidationResponse implements ValidationResponse { - - private LinkedHashMap errorMessageMap = new LinkedHashMap<>(); - - @Override - public boolean hasErrors() { - return errorMessageMap.size() != 0; - } - - @Override - public Set getFieldNamesWithError() { - return errorMessageMap.keySet(); - } - - public Collection getErrorMessageMap() { - return errorMessageMap.values(); - } - - @Override - public Map getValidationResultsAsMap() { - return errorMessageMap; - } - - - @Override - public String getAllErrorMessage() { - return getAllErrorMessage(","); - } - - @Override - public String getAllErrorMessage(String delimiter) { - return Joiner.on(delimiter).join(errorMessageMap.values()); - } - - @Override - public void addErrorMessage(String fieldName, String filedErrorMessage) { - errorMessageMap.put(fieldName, filedErrorMessage); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("hasErrors", hasErrors()) - .add("errorMessageMap", errorMessageMap) - .toString(); - } -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/ValidationResponse.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/ValidationResponse.java deleted file mode 100644 index b1b7a16..0000000 --- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/analytics/common/validation/ValidationResponse.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.validation; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * Validation Response contract - * - * @param Entity class type which is being validated - * - * @author Rajiv Singla. Creation Date: 10/24/2016. - */ -public interface ValidationResponse { - - /** - * Returns true if validation resulted in one or more errors - * - * @return true if validation has errors - */ - boolean hasErrors(); - - /** - * Returns all field names which have error - * - * @return names of fields which have error - */ - Set getFieldNamesWithError(); - - /** - * Returns list of all error messages - * - * @return list of error messages - */ - Collection getErrorMessageMap(); - - - /** - * Returns all error messages as string delimited by comma - * - * @return all error messages delimited by given delimiter - */ - String getAllErrorMessage(); - - /** - * Returns all error messages as string delimited by given delimited - * - * @param delimiter delimited to be used for error message - * @return all error messages delimited by given delimiter - */ - String getAllErrorMessage(String delimiter); - - /** - * Adds field name and error message to the validation response - * - * @param fieldName field name which has validation error - * @param filedErrorMessage validation error message - */ - void addErrorMessage(String fieldName, String filedErrorMessage); - - - /** - * Returns validation results as map containing values as keys and values - * as error Message - * - * @return Map containing field names and error message associated with those fields - */ - Map getValidationResultsAsMap(); - -} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/AnalyticsConstants.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/AnalyticsConstants.java new file mode 100644 index 0000000..4294d6a --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/AnalyticsConstants.java @@ -0,0 +1,134 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common; + +/** + * Contains static variable for all DCAE Components. + * + * @author Rajiv Singla. Creation Date: 10/21/2016. + */ +public abstract class AnalyticsConstants { + + + // =============== Common Constants for all DCAE Analytics Modules ==================== // + + + // =============== DMaaP Constants for all DCAE Analytics Modules ==================== // + + public static final String DMAAP_URI_PATH_PREFIX = "/events/"; + public static final String DMAAP_GROUP_PREFIX = "OpenDCAE-"; + + // ================== DMaaP MR Constants ============================== // + // Publisher Constants + public static final int DEFAULT_PUBLISHER_MAX_BATCH_SIZE = 100; + public static final int DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 100000; + public static final int PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE = 5; + public static final int PUBLISHER_DELAY_MS_ON_RETRIES_ON_CLOSE = 5000; + // Subscriber Constants + public static final int DEFAULT_SUBSCRIBER_TIMEOUT_MS = -1; + public static final int DEFAULT_SUBSCRIBER_MESSAGE_LIMIT = -1; + public static final String DEFAULT_SUBSCRIBER_GROUP_PREFIX = DMAAP_GROUP_PREFIX + "DMaaPSub-"; + public static final String SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME = "timeout"; + public static final String SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME = "limit"; + + + // ================== TCA Constants ============================== // + + // Default subscriber polling interval + public static final Integer TCA_DEFAULT_SUBSCRIBER_POLLING_INTERVAL_MS = 30000; + + // Default publisher polling interval + public static final Integer TCA_DEFAULT_PUBLISHER_POLLING_INTERVAL_MS = 30000; + + // Default publisher max batch queue size determines the minimum number of messages that need to be published in + // batch mode + public static final Integer TCA_DEFAULT_PUBLISHER_MAX_BATCH_QUEUE_SIZE = 10; + + // Default publisher max recovery queue size determines max number of messages can be cached in memory + // in case publisher is not responding + public static final Integer TCA_DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 100000; + + // Default interval during which TCA DMaaP Worker checks if scheduler is shut down + public static final Integer TCA_DEFAULT_WORKER_SHUTDOWN_CHECK_INTERVAL_MS = 10000; + + // ***** TCA Quartz Scheduler Settings ******// + + public static final String TCA_QUARTZ_SUBSCRIBER_PROPERTIES_FILE_NAME = "quartz-subscriber.properties"; + + public static final String TCA_QUARTZ_PUBLISHER_PROPERTIES_FILE_NAME = "quartz-publisher.properties"; + + // TCA Quartz Group Settings + public static final String TCA_QUARTZ_GROUP_NAME = "TCAQuartzGroup"; + // TCA Quartz Trigger Settings + public static final String TCA_DMAAP_SUBSCRIBER_QUARTZ_TRIGGER_NAME = "TCADMaaPSubscriberTrigger"; + public static final String TCA_DMAAP_PUBLISHER_QUARTZ_TRIGGER_NAME = "TCADMaaPPublisherTrigger"; + + // TCA Quartz DMaaP Subscriber Job Settings + public static final String TCA_DMAAP_SUBSCRIBER_QUARTZ_JOB_NAME = "TCADMaaPSubscriberJob"; + public static final String TCA_DMAAP_PUBLISHER_QUARTZ_JOB_NAME = "TCADMaaPPublisherJob"; + + // TCA Quartz Publisher and Subscriber Job Parameters + // Common Job parameters for both Publisher and Subscriber + public static final String WORKER_CONTEXT_VARIABLE_NAME = "WORKER_CONTEXT"; + public static final String DMAAP_METRICS_VARIABLE_NAME = "DMAAP_METRICS"; + // TCA Quartz DMaaP Subscriber Job Parameter Settings + public static final String CDAP_STREAM_VARIABLE_NAME = "CDAP_STREAM_NAME"; + public static final String DMAAP_SUBSCRIBER_VARIABLE_NAME = "DMAAP_SUBSCRIBER"; + // TCA Quartz DMaaP Publisher Job Parameter Settings + public static final String CDAP_ALERTS_TABLE_VARIABLE_NAME = "CDAP_TCA_ALERTS_TABLE_NAME"; + public static final String DMAAP_PUBLISHER_VARIABLE_NAME = "DMAAP_PUBLISHER"; + + // TCA VES Response Constants + public static final String TCA_VES_RESPONSE_TARGET_TYPE = "VNF"; + public static final String TCA_VES_RESPONSE_TARGET = "generic-vnf.vnf-id"; + public static final String TCA_VES_RESPONSE_FROM = "DCAE"; + public static final String TCA_VES_RESPONSE_CLOSED_LOOP_EVENT_STATUS = "ONSET"; + + // TCA VES Response Constants for vLoadBalancer + public static final String LOAD_BALANCER_FUNCTIONAL_ROLE = "vLoadBalancer"; + public static final String LOAD_BALANCER_TCA_VES_RESPONSE_TARGET_TYPE = "VM"; + public static final String LOAD_BALANCER_TCA_VES_RESPONSE_TARGET = "vserver.vserver-name"; + + // TCA VES Message Router Partition Key + public static final String TCA_VES_MESSAGE_ROUTER_PARTITION_KEY = "VESMessageHash"; + + /** + * Default Number of instances for Threshold violation calculator flowlet + */ + public static final Integer TCA_DEFAULT_THRESHOLD_CALCULATOR_FLOWLET_INSTANCES = 2; + + /** + * Default TTL for TCA VES Message status table which contain status of all messages processed by TCA + */ + public static final Integer TCA_DEFAULT_VES_MESSAGE_STATUS_TTL_TABLE = 60 * 60 * 24 * 10; // 10 Days + + /** + * Default TTL for TCA VES Alerts table which contains alerts that can be send to downstream systems + */ + public static final Integer TCA_DEFAULT_VES_ALERTS_TTL_TABLE = 60 * 60 * 24 * 20; // 20 Days + + + // TCA Policy Runtime Argument Paths + public static final String TCA_POLICY_DELIMITER = "."; + public static final String TCA_POLICY_DOMAIN_PATH = "domain"; + public static final String TCA_POLICY_METRICS_PER_FUNCTIONAL_ROLE_PATH = "configuration.metricsPerFunctionalRole"; + public static final String TCA_POLICY_THRESHOLDS_PATH_POSTFIX = "thresholds"; +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPComponentsConstants.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPComponentsConstants.java new file mode 100644 index 0000000..ab39ee9 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPComponentsConstants.java @@ -0,0 +1,196 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common; + +/** + * Contains static constant variable names and values of all DCAE CDAP Components for + * e.g. app names, app descriptions, streams, datasets, flows, flowlets, workers, outputs etc. + * + *

+ * A strict naming convention must be followed for variable names for CDAP Components names for proper + * identification of CDAP Component variable purpose and function. A custom configuration settings can be + * generated for app + * deployment purposes based on variable naming conventions. + * + * The variable names should have 4 parts separated by an underscore: + *

    + *
  • Name of the DCAE sub module (e.g. TCA) to which variable is applicable
  • + *
  • Information about variable name: + *
      + *
    • FIXED - if variable value is fixed and cannot be changed
    • + *
    • DEFAULT - if variable name is default name and can be changed by cdap settings file + * when application is created
    • + *
    + *
  • + *
  • Actual Descriptive name about the CDAP component (may contain underscrores)
  • + *
  • CDAP component type e.g STREAM, DATASET, APP, FLOW, FLOWLET, OUTPUT
  • + *
+ * + *

e.g TCA_DEFAULT_DMAAP_INPUT_STREAM

+ * + *

RegEx Format (DCAE MODULE NAME)_(FIXED|DEFAULT)_(VARIABLE NAME)_(CDAP COMPONENT TYPE)

+ * + * @author Rajiv Singla. Creation Date: 10/24/2016. + */ +public abstract class CDAPComponentsConstants { + + // =============== Common Module Constants ==================== // + + /** + * Default DCAE App Name. It should be overriden by sub modules + */ + public static final String COMMON_DEFAULT_DCAE_CDAP_NAME_APP = "DCAE_ANALYTICS_GENERIC_APP"; + + /** + * Default DCAE App Description. It should be overriden by sub modules + */ + public static final String COMMON_DEFAULT_DCAE_CDAP_DESCRIPTION_APP = "DCAE ANALYTICS GENERIC APP DESCRIPTION"; + + // =============== TCA Module Constants ==================== // + + /** + * Default TCA application name if application name is not provided from startup configuration + */ + public static final String TCA_DEFAULT_NAME_APP = "dcae-tca"; + + /** + * Default TCA application description if not provided from startup configuration + */ + public static final String TCA_DEFAULT_DESCRIPTION_APP = "DCAE Analytics Threshold Crossing Alert Application"; + + /** + * Default TCA DMaaP Subscriber output stream name if not provided from startup configuration + */ + public static final String TCA_DEFAULT_SUBSCRIBER_OUTPUT_NAME_STREAM = "TCASubscriberOutputStream"; + + + /** + * Fixed TCA DMaaP Subscriber output stream description + */ + public static final String TCA_FIXED_SUBSCRIBER_OUTPUT_DESCRIPTION_STREAM = + "Stream which contains all message from VES Collector DMaaP MR topic"; + + + /** + * Fixed Name of TCA DMaaP Subscriber Worker - which will be fetching DMaaP Messages posting them to CDAP stream + */ + public static final String TCA_FIXED_DMAAP_SUBSCRIBER_WORKER = "TCADMaaPMRSubscriberWorker"; + + /** + * Fixed Description of TCA DMaaP Subscriber Worker + */ + public static final String TCA_FIXED_DMAAP_SUBSCRIBER_DESCRIPTION_WORKER = + "Fetches messages from DMaaP MR Topic at frequent intervals and writes them to a CDAP stream"; + + /** + * Fixed Name of TCA DMaaP Publisher Worker - which will be publishing messages to DMaaP MR + */ + public static final String TCA_FIXED_DMAAP_PUBLISHER_WORKER = "TCADMaaPMRPublisherWorker"; + + /** + * Fixed Description of TCA DMaaP Publisher Worker + */ + public static final String TCA_FIXED_DMAAP_PUBLISHER_DESCRIPTION_WORKER = + "Polls TCA Alerts Table at frequent intervals for new alerts and publishes them to DMaaP MR Topic"; + + /** + * Fixed name for TCA VES Collector Messages Processing Flow + */ + public static final String TCA_FIXED_VES_COLLECTOR_NAME_FLOW = "TCAVESCollectorFlow"; + + + /** + * Fixed description for TCA VES Collector Messages Processing Flow + */ + public static final String TCA_FIXED_VES_COLLECTOR_DESCRIPTION_FLOW = "Flow performs TCA on VES Collector Messages"; + + + /** + * Fixed Name for TCA VES Message Router Flowlet + */ + public static final String TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET = "TCAVESMessageRouterFlowlet"; + + /** + * Fixed Description for TCA VES Message Router Flowlet + */ + public static final String TCA_FIXED_VES_MESSAGE_ROUTER_DESCRIPTION_FLOWLET = + "Routes message received from TCA VES Collector to TCA Threshold Calculator Flowlet instances"; + + /** + * Fixed TCA VES Message Router Flowlet Output + */ + public static final String TCA_FIXED_VES_MESSAGE_ROUTER_OUTPUT = "TCAVESMessageRouterFlowlet"; + + /** + * Fixed Name for TCA VES Message Policy Violated Threshold Calculator Flowlet + */ + public static final String TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_NAME_FLOWLET = + "TCAVESThresholdViolationCalculatorFlowlet"; + + /** + * Fixed Description for TCA VES Message Policy Violated Threshold Calculator Flowlet + */ + public static final String TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_DESCRIPTION_FLOWLET = + "Applies TCA Policy Thresholds to VES Message and determined if any message violated TCA Policy thresholds"; + + /** + * Fixed Name for TCA VES Message Policy Violated Threshold Calculator Output + */ + public static final String TCA_FIXED_VES_TCA_CALCULATOR_NAME_OUTPUT = "TCAThresholdViolationCalculatorOutput"; + + + /** + * Fixed Name for TCA VES Alerts Sink Flowlet + */ + public static final String TCA_FIXED_VES_ALERTS_SINK_NAME_FLOWLET = "TCAVESAlertsSinkFlowlet"; + + /** + * Fixed Description for TCA VES Alerts Sink Flowlet + */ + public static final String TCA_FIXED_VES_ALERTS_SINK_DESCRIPTION_FLOWLET = + "Saves messages which violated TCA Policy in a data set"; + + + /** + * Default Name for TCA VES Message status table which contain status of all messages processed by TCA + */ + public static final String TCA_DEFAULT_VES_MESSAGE_STATUS_NAME_TABLE = "TCAVESMessageStatusTable"; + + + /** + * Fixed Description for TCA VES Message status table which contain status of all messages processed by TCA + */ + public static final String TCA_FIXED_VES_MESSAGE_STATUS_DESCRIPTION_TABLE = + "Store processing information about all incoming TCA VES Messages"; + + /** + * Default Name for TCA VES Alerts table which contains alerts that can be send to downstream systems + */ + public static final String TCA_DEFAULT_VES_ALERTS_NAME_TABLE = "TCAVESAlertsTable"; + + /** + * Fixed Description for TCA VES Alerts table which contains alerts that can be send to downstream systems + */ + public static final String TCA_DEFAULT_VES_ALERTS_DESCRIPTION_TABLE = + "Stores alert messages that need to be DMaaP"; + + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPMetricsConstants.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPMetricsConstants.java new file mode 100644 index 0000000..63ac7e0 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/CDAPMetricsConstants.java @@ -0,0 +1,112 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common; + +/** + * Contains all metrics names used for DCAE CDAP modules + * + *

+ * Format should be (ModuleName)_(Description of metrics)_METRIC e.g. TCA_WORKER_FAILED_ATTEMPTS_METRIC + *

+ * + * @author Rajiv Singla. Creation Date: 10/25/2016. + */ +public abstract class CDAPMetricsConstants { + + /** + * Metric captures count of all responses received from DMaaP MR Subscriber Topic + */ + public static final String TCA_SUBSCRIBER_ALL_RESPONSES_COUNT_METRIC = "tca.subscriber.fetch.all_responses"; + + /** + * Metric captures count of responses from DMaaP MR Subscriber Topic which does not have 200 HTTP Response code. + * This can be due to DMaaP topic being down or any internal server errors etc. + */ + public static final String TCA_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC = "tca.subscriber.fetch.unsuccessful"; + + /** + * Metric that counts the number of successful (200 HTTP Response Code) calls to DMaaP which did not had empty + * messages + */ + public static final String TCA_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC = "tca.subscriber.fetch.no_message"; + + /** + * Metric to count total number of VES Collector message processed by tca subscriber + */ + public static final String TCA_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC = "tca.subscriber.message.count"; + + + /** + * Metric to record time taken in ms by subscriber in its most recent call to fetch DMaaP MR messages + */ + public static final String TCA_SUBSCRIBER_RESPONSE_TIME_MS_METRIC = "tca.subscriber.fetch.response_time"; + + /** + * Metric captures the count of number of times DMaaP MR Subscriber was unable to write to DMaaP Stream due + * some CDAP error while writing to stream. This should ideally never happen assuming we have enough space + * on CDAP machine and CDAP process is functioning normally + */ + public static final String TCA_SUBSCRIBER_FAILURE_TO_WRITE_TO_STREAM_METRIC = "tca.subscriber.stream.writing.error"; + + + /** + * Metric captures number of VES messages that are not applicable as per TCA Policy + */ + public static final String TCA_VES_INAPPLICABLE_MESSAGES_METRIC = "tca.ves.calculator.inapplicable"; + + /** + * Metric captures number of VES messages that are applicable as per TCA Policy but don't violate any thresholds + */ + public static final String TCA_VES_COMPLIANT_MESSAGES_METRIC = "tca.ves.calculator.compliant"; + + /** + * Metrics captures number of VES messages that are applicable as per TCA Policy and does violate thresholds and + * will likely cause an alert + */ + public static final String TCA_VES_NON_COMPLIANT_MESSAGES_METRIC = "tca.ves.calculator.non_compliant"; + + + /** + * Metric that counts the number of publisher look ups in alerts table which resulted in 0 new alerts + */ + public static final String TCA_PUBLISHER_NO_NEW_ALERTS_LOOKUP_METRIC = "tca.publisher.lookup.no_message"; + + /** + * Metric that counts the number of new alerts found by the publisher in alerts table + */ + public static final String TCA_PUBLISHER_NEW_ALERTS_METRIC = "tca.publisher.lookup.new_messages"; + + /** + * Metric that counts the number of alerts deleted by publisher in alerts table + */ + public static final String TCA_PUBLISHER_DELETED_ALERTS_METRIC = "tca.publisher.deleted.alerts"; + + /** + * Metric that counts the number of publisher calls to DMaaP which resulted in successful response code + */ + public static final String TCA_PUBLISHER_SUCCESSFUL_DMAAP_RESPONSE_METRIC = "tca.publisher.publish.successful"; + + /** + * Metric that counts the number of publisher calls to DMaaP which resulted in unsuccessful response code + */ + public static final String TCA_PUBLISHER_UNSUCCESSFUL_DMAAP_RESPONSE_METRIC = "tca.publisher.publish.unsuccessful"; + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/DCAEAnalyticsPreferences.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/DCAEAnalyticsPreferences.java new file mode 100644 index 0000000..c912179 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/DCAEAnalyticsPreferences.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common; + +/** + * A Marker Interface for all DCAE Analytics Preferences + * + * @author Rajiv Singla. Creation Date: 10/26/2016. + */ +public interface DCAEAnalyticsPreferences { +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppConfig.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppConfig.java new file mode 100644 index 0000000..a47170f --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppConfig.java @@ -0,0 +1,47 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.cdap.settings; + +/** + *

+ * Minimum Contract for all CDAP App Configs + *

+ * + * @author Rajiv Singla. Creation Date: 11/2/2016. + */ +public interface CDAPAppConfig extends CDAPAppSettings { + + /** + * CDAP Application Name + * + * @return cdap app name + */ + String getAppName(); + + + /** + * CDAP Application Description + * + * @return cdap app description + */ + String getAppDescription(); + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppPreferences.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppPreferences.java new file mode 100644 index 0000000..67fbfc1 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppPreferences.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.cdap.settings; + +/** + *

+ * Marker Interface for all CDAP Preferences + *

+ * + * @author Rajiv Singla. Creation Date: 11/2/2016. + */ +public interface CDAPAppPreferences extends CDAPAppSettings { +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppSettings.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppSettings.java new file mode 100644 index 0000000..9e96cfe --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPAppSettings.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.cdap.settings; + +import java.io.Serializable; + +/** + *

+ * A marker interface for all CDAP Related App Settings. + * App Settings can either be preferences, cdap app settings etc. + *

+ * + * + * @author Rajiv Singla. Creation Date: 11/2/2016. + */ +public interface CDAPAppSettings extends Serializable { +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPBaseAppConfig.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPBaseAppConfig.java new file mode 100644 index 0000000..38c882f --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/settings/CDAPBaseAppConfig.java @@ -0,0 +1,62 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.cdap.settings; + +import co.cask.cdap.api.Config; +import org.openecomp.dcae.apod.analytics.common.CDAPComponentsConstants; + +/** + * Base class for all DACE Analytics Application Configurations + * + * @author Rajiv Singla. Creation Date: 10/4/2016. + */ +public abstract class CDAPBaseAppConfig extends Config implements CDAPAppConfig { + + + /** + * DCAE Analytics App Name + */ + protected String appName = CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_NAME_APP; + + /** + * DCAE Analytics App Description + */ + protected String appDescription = CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_DESCRIPTION_APP; + + + /** + * Returns DCAE Analytics CDAP Application name + * + * @return CDAP application name + */ + public String getAppName() { + return appName; + } + + /** + * Returns DCAE Analytics CDAP Application descrption + * + * @return CDAP application description + */ + public String getAppDescription() { + return appDescription; + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/validation/CDAPAppSettingsValidator.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/validation/CDAPAppSettingsValidator.java new file mode 100644 index 0000000..7ebe8e3 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/cdap/validation/CDAPAppSettingsValidator.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.cdap.validation; + +import org.openecomp.dcae.apod.analytics.common.cdap.settings.CDAPAppSettings; +import org.openecomp.dcae.apod.analytics.common.validation.DCAEValidator; +import org.openecomp.dcae.apod.analytics.common.validation.ValidationResponse; + +/** + *

+ * Validates CDAP Application Settings (AppConfig, Preferences etc) + *

+ * + * @param {@link CDAPAppSettings} DCAE Analytics App Settings (e.g. AppConfig, Preferences) + * @param {@link ValidationResponse} Validator response implementations + * + * @author Rajiv Singla. Creation Date: 11/2/2016. + */ +public interface CDAPAppSettingsValidator> + extends DCAEValidator { + + /** + * Validates DCAE Analytics App Settings and return Validation response which can be + * checked for any app setting issues + * + * @param appSettings DCAE CDAP Application Settings (e.g. AppConfig, Preferences etc.) + * @return validation response + */ + R validateAppSettings(T appSettings); + + +} + + diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/CDAPSettingsException.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/CDAPSettingsException.java new file mode 100644 index 0000000..f5a8037 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/CDAPSettingsException.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.exception; + +import org.slf4j.Logger; + +/** + * Runtime exception which signals that DCAE CDAP App settings (e.g. app config, preferences) validation failed + * + * @author Rajiv Singla. Creation Date: 10/24/2016. + */ +public class CDAPSettingsException extends DCAEAnalyticsRuntimeException { + + /** + * @param message - Error Message for Exception + * @param cause - Actual Exception which caused {@link DCAEAnalyticsRuntimeException} + */ + public CDAPSettingsException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Creates and logs the DCAE App Config Exception to given logger + * + * @param message - Error Message for Exception and logging + * @param logger - Logger used for logging exception + * @param cause - Actual exception which caused + */ + public CDAPSettingsException(String message, Logger logger, Throwable cause) { + super(message, logger, cause); + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/DCAEAnalyticsRuntimeException.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/DCAEAnalyticsRuntimeException.java new file mode 100644 index 0000000..559e6ae --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/DCAEAnalyticsRuntimeException.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.exception; + +import org.slf4j.Logger; + +/** + * Runtime Exception for DCAE Analytics Exceptions. All DCAE Analytics + * runtime Exceptions must be wrapped inside this exception + *

+ * @author Rajiv Singla. Creation Date: 10/5/2016. + */ +public class DCAEAnalyticsRuntimeException extends RuntimeException { + + + /** + * @param message - Error Message for Exception + * @param cause - Actual Exception which caused {@link DCAEAnalyticsRuntimeException} + */ + public DCAEAnalyticsRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Creates and logs the DCAE Runtime Exception to given logger + * + * @param message - Error Message for Exception and logging + * @param logger - Logger used for logging exception + * @param cause - Actual exception which caused {@link DCAEAnalyticsRuntimeException} + */ + public DCAEAnalyticsRuntimeException(String message, Logger logger, Throwable cause) { + super(message, cause); + logger.error(message); + } + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/MessageProcessingException.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/MessageProcessingException.java new file mode 100644 index 0000000..44ef147 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/exception/MessageProcessingException.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.exception; + +import org.openecomp.dcae.apod.analytics.common.service.processor.MessageProcessor; +import org.slf4j.Logger; + +/** + * Runtime Exception caused due to {@link MessageProcessor} failure while processing a message. + * + * @author Rajiv Singla. Creation Date: 11/7/2016. + */ +public class MessageProcessingException extends DCAEAnalyticsRuntimeException { + + /** + * @param message - Error Message for Exception + * @param cause - Actual Exception which caused {@link DCAEAnalyticsRuntimeException} + */ + public MessageProcessingException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Creates and logs the DCAE Runtime Exception to given logger + * + * @param message - Error Message for Exception and logging + * @param logger - Logger used for logging exception + * @param cause - Actual exception which caused {@link DCAEAnalyticsRuntimeException} + */ + public MessageProcessingException(String message, Logger logger, Throwable cause) { + super(message, logger, cause); + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessor.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessor.java new file mode 100644 index 0000000..c90858a --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessor.java @@ -0,0 +1,162 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import com.google.common.base.Optional; +import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; + +import static java.lang.String.format; + +/** + * An abstract Message Processor which can be extended by {@link MessageProcessor} implementations + * to get default behavior for Message Processors + * + * @param

Processor Context sub classes + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public abstract class AbstractMessageProcessor

implements MessageProcessor

{ + + private static final Logger LOG = LoggerFactory.getLogger(AbstractMessageProcessor.class); + + /** + * By Default there is no processing message + */ + private String processingMessage = null; + + /** + * By Default Processing State is set to not required - subclasses must + * set processing state to {@link ProcessingState#PROCESSING_FINISHED_SUCCESSFULLY} on successful processing + * or {@link ProcessingState#PROCESSING_TERMINATED_EARLY} if processing fails + */ + protected ProcessingState processingState = ProcessingState.PROCESSING_NOT_REQUIRED; + + /** + * Sub classes must provide a description of a processor + * + * @return description of processor + * + */ + public abstract String getProcessorDescription(); + + + /** + * Sub classes must provide implementation to process Message + * + * @param processorContext incoming {@link ProcessorContext} + * @return outgoing {@link ProcessorContext} + */ + public abstract P processMessage(P processorContext); + + @Override + public ProcessorInfo getProcessorInfo() { + // by default the class of the Processor is assigned as Processor Name + final String processorClassName = getClass().getSimpleName(); + return new GenericProcessorInfo(processorClassName, getProcessorDescription()); + } + + @Override + public P preProcessor(P processorContext) { + LOG.debug("Processing Started for Processor: {}", getProcessorInfo().getProcessorName()); + // by default check to see if continue processing Flag is not false + final boolean okToContinue = processorContext.canProcessingContinue(); + if (!okToContinue) { + final String errorMessage = + format("Processor: %s. Processing Context flag okToContinue is false. Unable to proceed...", + getProcessorInfo().getProcessorName()); + throw new MessageProcessingException(errorMessage, LOG, new IllegalStateException(errorMessage)); + } + processingState = ProcessingState.PROCESSING_STARTED; + return processorContext; + } + + @Override + public ProcessingState getProcessingState() { + return processingState; + } + + @Override + public Optional getProcessingMessage() { + return Optional.fromNullable(processingMessage); + } + + @Override + public P postProcessor(P processorContext) { + // Default implementation updates the post processing flag if processing did not + // completed successfully + if (processingState != ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY) { + LOG.debug("Processor: {}, Update Process Context State to stop Processing.", + getProcessorInfo().getProcessorName()); + processorContext.setProcessingContinueFlag(false); + } + // attaches itself to message processor context + processorContext.getMessageProcessors().add(this); + LOG.debug("Processing Completed for Processor: {}", getProcessorInfo()); + return processorContext; + } + + + @Override + public final P apply(@Nonnull P processorContext) { + final P preProcessedProcessorContext = preProcessor(processorContext); + final P processedProcessorContext = processMessage(preProcessedProcessorContext); + return postProcessor(processedProcessorContext); + } + + + /** + * Helper method that updates processing state in case of early termination, logs the processing + * termination reason, updates Processor processing state as Terminated and sets it processing message + * + * @param terminatingMessage error Message + * @param processorContext message processor context + */ + protected void setTerminatingProcessingMessage(final String terminatingMessage, + final P processorContext) { + + final String message = processorContext.getMessage(); + this.processingState = ProcessingState.PROCESSING_TERMINATED_EARLY; + this.processingMessage = terminatingMessage; + LOG.debug("Processor: {}, Early Terminating Message: {}, Incoming Message: {}", + getProcessorInfo().getProcessorName(), terminatingMessage, message); + } + + /** + * Helper method that updates Processing state and logs completion message + * passed + * + * @param processorPassingMessage Processor passing message + * @param processorContext message processor context + */ + protected void setFinishedProcessingMessage(final String processorPassingMessage, P processorContext) { + final String message = processorContext.getMessage(); + processingState = ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY; + this.processingMessage = processorPassingMessage; + LOG.debug("Processor: {}, Successful Completion Message: {}, Incoming Message: {}", + getProcessorInfo().getProcessorName(), processorPassingMessage, message); + } + + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContext.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContext.java new file mode 100644 index 0000000..2274f0e --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContext.java @@ -0,0 +1,96 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import com.google.common.base.Objects; + +import java.util.LinkedList; +import java.util.List; + +/** + *

+ * An abstract implementation for {@link ProcessorContext} which other DCAE Analytics Modules + * can extend to add module specific functionality + *

+ * + * @author Rajiv Singla. Creation Date: 11/7/2016. + */ +public abstract class AbstractProcessorContext implements ProcessorContext { + + private final String message; + private List> messageProcessors; + private boolean canProcessingContinue; + + public AbstractProcessorContext(final String message, + boolean canProcessingContinue) { + this.message = message; + this.canProcessingContinue = canProcessingContinue; + this.messageProcessors = new LinkedList<>(); + } + + /** + * Returns JSON String of incoming CEF Message that needs to be processed + * + * @return incoming CEF message that needs to be processed + */ + @Override + public String getMessage() { + return message; + } + + /** + * Sets if it is ok to continue processing normally + * + * @return boolean which determines if it is ok to continue processing normally + */ + @Override + public boolean canProcessingContinue() { + return canProcessingContinue; + } + + + /** + * Set if it is ok to continue processing normally + * + * @param canProcessingContinue sets boolean which determines if it is ok to continue processing normally + */ + @Override + public void setProcessingContinueFlag(boolean canProcessingContinue) { + this.canProcessingContinue = canProcessingContinue; + } + + /** + * Provides List of message processors which were used in processing CEF message + * + * @return List of message processors which were used in processing CEF message + */ + @Override + public List> getMessageProcessors() { + return messageProcessors; + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("canProcessingContinue", canProcessingContinue) + .toString(); + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessor.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessor.java new file mode 100644 index 0000000..b289a32 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessor.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import org.openecomp.dcae.apod.analytics.common.utils.MessageProcessorUtils; + +import java.util.List; + +/** + *

+ * A Generic Message Processor which passes the {@link ProcessorContext} from first to second + * {@link MessageProcessor} + *

+ * + * @param

Processor Context sub classes + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public class GenericMessageChainProcessor

{ + + private final List> messageProcessors; + private final P initialProcessorContext; + + public GenericMessageChainProcessor(List> messageProcessors, + P initialProcessorContext) { + this.messageProcessors = messageProcessors; + this.initialProcessorContext = initialProcessorContext; + } + + public P processChain() { + + final MessageProcessorUtils.MessageProcessorFunction

messageProcessorFunction = + new MessageProcessorUtils.MessageProcessorFunction

() { + @Override + public > P apply(P context, M processor) { + return processor.apply(context); + } + }; + + return MessageProcessorUtils.computeMessageProcessorChain(messageProcessors, initialProcessorContext, + messageProcessorFunction); + + } + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfo.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfo.java new file mode 100644 index 0000000..681bb4d --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfo.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import javax.annotation.Nonnull; + +/** + * A Generic Implementation of {@link ProcessorInfo} + * + * @author Rajiv Singla. Creation Date: 11/7/2016. + */ +public class GenericProcessorInfo implements ProcessorInfo { + + private static final long serialVersionUID = -2840512323233649809L; + + private final String processorName; + private final String processorDescription; + + public GenericProcessorInfo(@Nonnull String processorName, @Nonnull String processorDescription) { + this.processorName = processorName; + this.processorDescription = processorDescription; + } + + public String getProcessorName() { + return processorName; + } + + public String getProcessorDescription() { + return processorDescription; + } + + + @Override + public String toString() { + return processorName; + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/MessageProcessor.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/MessageProcessor.java new file mode 100644 index 0000000..73414db --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/MessageProcessor.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import com.google.common.base.Function; +import com.google.common.base.Optional; + +import java.io.Serializable; + +/** + *

+ * A message processor can be used to process incoming messages. + * It uses implementations of {@link ProcessorContext} as input and output + *

+ * + * @param

Message Processor Context implementations + * + * @author Rajiv Singla. Creation Date: 11/7/2016. + */ +public interface MessageProcessor

extends Function, Serializable { + + /** + * Returns processor information + * + * @return processor Information + */ + ProcessorInfo getProcessorInfo(); + + + /** + * Does pre-processing of {@link ProcessorContext} e.g. validate input conditions and return + * pre processed context + * + * @param processorContext incoming Processor Context + * @return Pre processed Processor Context + */ + P preProcessor(P processorContext); + + + /** + * Return processing state of a processor + * + * @return Processing State + */ + ProcessingState getProcessingState(); + + + /** + * May return a message from a processor which indicates the reason for {@link ProcessingState} especially if + * there was some failure in processing + * + * @return processing Message + */ + Optional getProcessingMessage(); + + + /** + * Does post-processing of {@link ProcessorContext} + * + * @param processorContext incoming Processor Context + * @return processor Context after post processing is finished + */ + P postProcessor(P processorContext); + + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessingState.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessingState.java new file mode 100644 index 0000000..8f97d63 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessingState.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +/** + *

+ * Processing state of a {@link MessageProcessor} + *

+ * @author Rajiv Singla. Creation Date: 11/5/2016. + */ +public enum ProcessingState { + + PROCESSING_STARTED, + PROCESSING_FINISHED_SUCCESSFULLY, + PROCESSING_TERMINATED_EARLY, + PROCESSING_NOT_REQUIRED; + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorContext.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorContext.java new file mode 100644 index 0000000..3c70919 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorContext.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import java.io.Serializable; +import java.util.List; + +/** + *

+ * A Processor Context is used a an input and output to a {@link MessageProcessor} + *
+ * DCAE Analytics sub projects should extend this interface and add specific fields + * required for input and output + *

+ * + * @author Rajiv Singla. Creation Date: 11/7/2016. + */ +public interface ProcessorContext extends Serializable { + + /** + * Returns Processor Context message that will be processed by Chain of Processors + * + * @return message that need to be processed by processors + */ + String getMessage(); + + /** + * Processing Context flag which determines if Processing can continue in a processing + * chain + * + * @return true if ok to continue processing normally + */ + boolean canProcessingContinue(); + + + /** + * Sets new value for ProcessingContinue flag which will cause early termination of processing in chain if + * set to false + * + * @param canProcessingContinue set new value for canProcessing Continue flag + */ + void setProcessingContinueFlag(boolean canProcessingContinue); + + + /** + * Provides a List of previous processors which have completed processing + * + * @return list of previous processors + */ + List> getMessageProcessors(); + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorInfo.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorInfo.java new file mode 100644 index 0000000..6bb74b0 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/processor/ProcessorInfo.java @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import java.io.Serializable; + +/** + *

+ * Contains Information about a processor. For e.g. Processor name, processor description etc + *

+ * + * @author Rajiv Singla. Creation Date: 11/7/2016. + */ +public interface ProcessorInfo extends Serializable { + + /** + * Returns a name which should uniquely identify a particular {@link MessageProcessor} + * + * @return processor name + */ + String getProcessorName(); + + + /** + * Returns description of a {@link MessageProcessor} + * + * @return processor description + */ + String getProcessorDescription(); + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtils.java new file mode 100644 index 0000000..c10935f --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtils.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.utils; + +/** + * Contains common utils to check HTTP Related Utils + * + * @author Rajiv Singla. Creation Date: 11/2/2016. + */ +public abstract class HTTPUtils { + + /** + * HTTP Status code for successful HTTP call + */ + public static final Integer HTTP_SUCCESS_STATUS_CODE = 200; + + /** + * HTTP Response code when request has been accepted for processing, but the processing has not been completed + */ + public static final Integer HTTP_ACCEPTED_RESPONSE_CODE = 202; + + /** + * HTTP Response code when there is no content + */ + public static final Integer HTTP_NO_CONTENT_RESPONSE_CODE = 204; + + + public static final String JSON_APPLICATION_TYPE = "application/json"; + + /** + * Checks if HTTP Status code is less than or equal to 200 but less then 300 + * + * @param statusCode http status code + * @return true if response code between 200 and 300 + */ + public static boolean isSuccessfulResponseCode(Integer statusCode) { + return statusCode >= 200 && statusCode < 300; + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtils.java new file mode 100644 index 0000000..20deb72 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtils.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.utils; + +import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException; +import org.openecomp.dcae.apod.analytics.common.service.processor.MessageProcessor; +import org.openecomp.dcae.apod.analytics.common.service.processor.ProcessorContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Iterator; + + +/** + * Contains utility methods for {@link MessageProcessor} + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public abstract class MessageProcessorUtils { + + private static final Logger LOG = LoggerFactory.getLogger(MessageProcessorUtils.class); + + /** + * Provides an abstraction how to apply {@link ProcessorContext} to next {@link MessageProcessor} + * in the message processor chain + * + * @param

Sub classes of Processor Context + */ + public interface MessageProcessorFunction

{ + + /** + * Method which provides accumulated {@link ProcessorContext} from previous processors and a reference + * to next processor in the chain + * + * @param p accumulated {@link ProcessorContext} from previous processors + * @param m current {@link MessageProcessor} in the chain + * @param Message processor sub classes + * + * @return processing context after computing the current Message Processor + */ + > P apply(P p, M m); + } + + + /** + * Provides an abstraction to compute a chain of {@link MessageProcessor} + * + * @param messageProcessors An iterable containing one or more {@link MessageProcessor}s + * @param initialProcessorContext An initial processing Context + * @param messageProcessorFunction messageProcessor Function + * @param

Sub classes for Processor Context + * + * @return processing context which results after computing the whole chain + */ + public static

P computeMessageProcessorChain( + final Iterable> messageProcessors, + final P initialProcessorContext, + final MessageProcessorFunction

messageProcessorFunction) { + + // Get message processor iterator + final Iterator> processorIterator = messageProcessors.iterator(); + + // If no next message processor - return initial processor context + if (!processorIterator.hasNext()) { + return initialProcessorContext; + } + + // An accumulator for processor Context + P processorContextAccumulator = initialProcessorContext; + + while (processorIterator.hasNext()) { + + final MessageProcessor

nextProcessor = processorIterator.next(); + + // If Initial Processor Context is null + if (processorContextAccumulator == null) { + final String errorMessage = + String.format("Processor Context must not be null for Message Process: %s", + nextProcessor.getProcessorInfo().getProcessorName()); + throw new MessageProcessingException(errorMessage, LOG, new IllegalStateException(errorMessage)); + } + + + if (!processorContextAccumulator.canProcessingContinue()) { + LOG.debug("Triggering Early Termination, before Message Processor: {}, Incoming Message: {}", + nextProcessor.getProcessorInfo().getProcessorName(), processorContextAccumulator.getMessage()); + break; + } + processorContextAccumulator = messageProcessorFunction.apply(processorContextAccumulator, nextProcessor); + } + + return processorContextAccumulator; + } + + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtils.java new file mode 100644 index 0000000..a10280f --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtils.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.utils; + +import java.util.Date; + +/** + * Contains Utility methods for creating persistence row keys etc. + * + * @author Rajiv Singla. Creation Date: 11/16/2016. + */ +public abstract class PersistenceUtils { + + + /** + * Name of the column which will contain Table Key + */ + public static final String TABLE_ROW_KEY_COLUMN_NAME = "key"; + + /** + * Delimited to be used when creating a row key with multiple fields + */ + public static final String ROW_KEY_DELIMITER = "-"; + + /** + * Creates a decreasing number using current timestamp. Handy when you want to keep records most recent records + * close to the top of column table like HBase + * + * @return decreasing number + */ + public static String getCurrentTimeReverseSubKey() { + final long timeReverseLong = Long.MAX_VALUE - new Date().getTime(); + return String.format("%025d", timeReverseLong); + } + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/ValidationUtils.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/ValidationUtils.java new file mode 100644 index 0000000..f4f50a7 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/utils/ValidationUtils.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.utils; + +import org.openecomp.dcae.apod.analytics.common.cdap.settings.CDAPAppSettings; +import org.openecomp.dcae.apod.analytics.common.cdap.validation.CDAPAppSettingsValidator; +import org.openecomp.dcae.apod.analytics.common.exception.CDAPSettingsException; +import org.openecomp.dcae.apod.analytics.common.validation.ValidationResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Contains utility methods to validate null checks, empty string etc + * + * @author Rajiv Singla. Creation Date: 10/24/2016. + */ +public abstract class ValidationUtils { + + private static final Logger LOG = LoggerFactory.getLogger(ValidationUtils.class); + + /** + * Checks if String is empty. For null string true is returned + * + * @param stringValue string value + * @return returns true is string is empty or null + */ + public static boolean isEmpty(final @Nullable String stringValue) { + return stringValue == null || stringValue.isEmpty() || stringValue.trim().isEmpty(); + } + + + /** + * Provides common functionality to Validates CDAP App Settings. Throws Runtime exception if validation fails + * + * @param appSettings app Settings e.g. App Config, App Preferences etc + * @param appSettingsValidator app Settings validator + * + * @param Settings type e.g. AppConfig or AppPreferences + * @param Validation Response type + * @param Validator Type + */ + public static , + V extends CDAPAppSettingsValidator> void validateSettings(final @Nonnull T appSettings, + final @Nonnull V appSettingsValidator) { + checkNotNull(appSettings, "App Settings must not be null"); + checkNotNull(appSettingsValidator, "App Settings validator must not be null"); + + final String appSettingsClassName = appSettings.getClass().getSimpleName(); + final String appSettingsClassValidator = appSettingsValidator.getClass().getSimpleName(); + + LOG.debug("Validating App Settings for: {}, with App Settings Validator: {} ", + appSettingsClassName, appSettingsClassValidator); + + final R validationResponse = appSettingsValidator.validateAppSettings(appSettings); + + // If setting validation fails throw an exception + if (validationResponse.hasErrors()) { + throw new CDAPSettingsException( + validationResponse.getAllErrorMessage(), LOG, new IllegalArgumentException()); + } + + LOG.debug("App Settings Validation Successful for app Settings: {} with validator: {}", appSettingsClassName, + appSettingsClassValidator); + } + +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/DCAEValidator.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/DCAEValidator.java new file mode 100644 index 0000000..a42b53a --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/DCAEValidator.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.validation; + +/** + * Marker interface for all DCAE Validators + * + * @author Rajiv Singla. Creation Date: 10/24/2016. + */ +public interface DCAEValidator { +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponse.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponse.java new file mode 100644 index 0000000..3acb0c8 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponse.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.validation; + +import com.google.common.base.Joiner; +import com.google.common.base.Objects; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + +/** + * A generic implementation of Validation Response + * + * @param Validation Entity Type + * + * @author Rajiv Singla. Creation Date: 10/24/2016. + */ +public class GenericValidationResponse implements ValidationResponse { + + private LinkedHashMap errorMessageMap = new LinkedHashMap<>(); + + @Override + public boolean hasErrors() { + return errorMessageMap.size() != 0; + } + + @Override + public Set getFieldNamesWithError() { + return errorMessageMap.keySet(); + } + + public Collection getErrorMessageMap() { + return errorMessageMap.values(); + } + + @Override + public Map getValidationResultsAsMap() { + return errorMessageMap; + } + + + @Override + public String getAllErrorMessage() { + return getAllErrorMessage(","); + } + + @Override + public String getAllErrorMessage(String delimiter) { + return Joiner.on(delimiter).join(errorMessageMap.values()); + } + + @Override + public void addErrorMessage(String fieldName, String filedErrorMessage) { + errorMessageMap.put(fieldName, filedErrorMessage); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("hasErrors", hasErrors()) + .add("errorMessageMap", errorMessageMap) + .toString(); + } +} diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/ValidationResponse.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/ValidationResponse.java new file mode 100644 index 0000000..11591a3 --- /dev/null +++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/validation/ValidationResponse.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.validation; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +/** + * Validation Response contract + * + * @param Entity class type which is being validated + * + * @author Rajiv Singla. Creation Date: 10/24/2016. + */ +public interface ValidationResponse { + + /** + * Returns true if validation resulted in one or more errors + * + * @return true if validation has errors + */ + boolean hasErrors(); + + /** + * Returns all field names which have error + * + * @return names of fields which have error + */ + Set getFieldNamesWithError(); + + /** + * Returns list of all error messages + * + * @return list of error messages + */ + Collection getErrorMessageMap(); + + + /** + * Returns all error messages as string delimited by comma + * + * @return all error messages delimited by given delimiter + */ + String getAllErrorMessage(); + + /** + * Returns all error messages as string delimited by given delimited + * + * @param delimiter delimited to be used for error message + * @return all error messages delimited by given delimiter + */ + String getAllErrorMessage(String delimiter); + + /** + * Adds field name and error message to the validation response + * + * @param fieldName field name which has validation error + * @param filedErrorMessage validation error message + */ + void addErrorMessage(String fieldName, String filedErrorMessage); + + + /** + * Returns validation results as map containing values as keys and values + * as error Message + * + * @return Map containing field names and error message associated with those fields + */ + Map getValidationResultsAsMap(); + +} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/BaseAnalyticsCommonUnitTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/BaseAnalyticsCommonUnitTest.java deleted file mode 100644 index 06b7e63..0000000 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/BaseAnalyticsCommonUnitTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common; - -import org.openecomp.dcae.analytics.common.service.processor.TestEarlyTerminatingProcessor; -import org.openecomp.dcae.analytics.common.service.processor.TestMessageProcessor1; -import org.openecomp.dcae.analytics.common.service.processor.TestMessageProcessor2; -import org.openecomp.dcae.analytics.common.service.processor.TestProcessorContext; -import org.openecomp.dcae.analytics.test.BaseDCAEAnalyticsUnitTest; - -/** - * Base class from all DCEA Analytics Common Module Unit Tests - *

- * @author Rajiv Singla. Creation Date: 10/6/2016. - */ -public abstract class BaseAnalyticsCommonUnitTest extends BaseDCAEAnalyticsUnitTest { - - - protected TestProcessorContext testProcessorContext = new TestProcessorContext("", true); - - protected TestMessageProcessor1 getTestMessageProcessor1() { - return new TestMessageProcessor1(); - } - protected TestMessageProcessor2 getTestMessageProcessor2() { - return new TestMessageProcessor2(); - } - protected TestEarlyTerminatingProcessor getTestEarlyTerminationProcessor() { - return new TestEarlyTerminatingProcessor(); - } -} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessorTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessorTest.java deleted file mode 100644 index 2ab9d40..0000000 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/GenericMessageChainProcessorTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import com.google.common.collect.ImmutableList; -import org.junit.Test; -import org.openecomp.dcae.analytics.common.BaseAnalyticsCommonUnitTest; -import org.openecomp.dcae.analytics.common.exception.MessageProcessingException; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - - -/** - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public class GenericMessageChainProcessorTest extends BaseAnalyticsCommonUnitTest { - - - @Test - public void testProcessChainWhenProcessChainHasNoEarlyTermination() throws Exception { - - final TestMessageProcessor1 testMessageProcessor1 = getTestMessageProcessor1(); - final TestMessageProcessor2 testMessageProcessor2 = getTestMessageProcessor2(); - final ImmutableList> testMessageChain = - ImmutableList.of(testMessageProcessor1, testMessageProcessor2); - - final TestProcessorContext testProcessorContext = new TestProcessorContext("Hello", true); - - final GenericMessageChainProcessor genericMessageChainProcessor = - new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); - - final TestProcessorContext finalProcessorContext = genericMessageChainProcessor.processChain(); - - final String result = finalProcessorContext.getResult(); - assertThat("Final Result must be Hello World! Again", result, is("Hello World! Again")); - assertThat("TestProcessor1 state is correct", testMessageProcessor1.getProcessingState(), - is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY)); - assertThat("TestProcessor2 state is correct", testMessageProcessor2.getProcessingState(), - is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY)); - } - - - @Test - public void testProcessChainWhenProcessChainEarlyTermination() throws Exception { - - final TestEarlyTerminatingProcessor testEarlyTerminatingProcessor = getTestEarlyTerminationProcessor(); - final ImmutableList> testMessageChain = - ImmutableList.of(testEarlyTerminatingProcessor, getTestMessageProcessor2()); - final TestProcessorContext testProcessorContext = new TestProcessorContext("Hello", true); - - final GenericMessageChainProcessor genericMessageChainProcessor = - new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); - - final TestProcessorContext finalProcessorContext = genericMessageChainProcessor.processChain(); - final String result = finalProcessorContext.getResult(); - assertNull("Final Result must be null", result); - assertThat("TestEarlyTerminatingProcessor state is correct", - testEarlyTerminatingProcessor.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY)); - } - - @Test(expected = MessageProcessingException.class) - public void testProcessChainWhenIncomingMessageContextIsNull() throws Exception { - - final TestEarlyTerminatingProcessor testEarlyTerminatingProcessor = getTestEarlyTerminationProcessor(); - final ImmutableList> testMessageChain = - ImmutableList.of(testEarlyTerminatingProcessor, getTestMessageProcessor2()); - final TestProcessorContext testProcessorContext = null; - - final GenericMessageChainProcessor genericMessageChainProcessor = - new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); - - genericMessageChainProcessor.processChain(); - } - -} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestEarlyTerminatingProcessor.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestEarlyTerminatingProcessor.java deleted file mode 100644 index c5852de..0000000 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestEarlyTerminatingProcessor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -/** - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public class TestEarlyTerminatingProcessor extends AbstractMessageProcessor { - - @Override - public String getProcessorDescription() { - return "Terminates the chain early"; - } - - @Override - public TestProcessorContext processMessage(TestProcessorContext processorContext) { - setTerminatingProcessingMessage("Terminating early", processorContext); - return processorContext; - } -} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor1.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor1.java deleted file mode 100644 index 6c56cb8..0000000 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor1.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -/** - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public class TestMessageProcessor1 extends AbstractMessageProcessor { - - @Override - public String getProcessorDescription() { - return "Appends \" World!\" to the message string and set it to result string"; - } - - @Override - public TestProcessorContext processMessage(TestProcessorContext processorContext) { - final String message = processorContext.getMessage(); - processorContext.setResult(message + " World!"); - setFinishedProcessingMessage("Finished Appending world", processorContext); - return processorContext; - } -} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor2.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor2.java deleted file mode 100644 index 0ecbedf..0000000 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestMessageProcessor2.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -/** - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public class TestMessageProcessor2 extends AbstractMessageProcessor { - - @Override - public String getProcessorDescription() { - return "Appends \" Again\" to the result string"; - } - - @Override - public TestProcessorContext processMessage(TestProcessorContext processorContext) { - final String result = processorContext.getResult(); - processorContext.setResult(result + " Again"); - setFinishedProcessingMessage("Finished Appending again to result", processorContext); - return processorContext; - } -} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestProcessorContext.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestProcessorContext.java deleted file mode 100644 index 9d9342f..0000000 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/analytics/common/service/processor/TestProcessorContext.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.common.service.processor; - -import java.util.LinkedList; -import java.util.List; - -/** - * - * @author Rajiv Singla. Creation Date: 11/8/2016. - */ -public class TestProcessorContext implements ProcessorContext { - - private String message; - private boolean continueProcessingFlag; - private String result; - private List> messageProcessors; - - public TestProcessorContext(String message, boolean continueProcessingFlag) { - this.message = message; - this.continueProcessingFlag = continueProcessingFlag; - this.messageProcessors = new LinkedList<>(); - } - - @Override - public String getMessage() { - return message; - } - - @Override - public boolean canProcessingContinue() { - return continueProcessingFlag; - } - - @Override - public void setProcessingContinueFlag(boolean canProcessingContinue) { - this.continueProcessingFlag = canProcessingContinue; - } - - @Override - public List> getMessageProcessors() { - return messageProcessors; - } - - - public void setMessage(String message) { - this.message = message; - } - - public boolean isContinueProcessingFlag() { - return continueProcessingFlag; - } - - public void setContinueProcessingFlag(boolean continueProcessingFlag) { - this.continueProcessingFlag = continueProcessingFlag; - } - - public String getResult() { - return result; - } - - public void setResult(String result) { - this.result = result; - } - -} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java new file mode 100644 index 0000000..bd38168 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common; + +import org.openecomp.dcae.apod.analytics.common.service.processor.TestEarlyTerminatingProcessor; +import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor1; +import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor2; +import org.openecomp.dcae.apod.analytics.common.service.processor.TestProcessorContext; +import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest; + +/** + * Base class from all DCEA Analytics Common Module Unit Tests + *

+ * @author Rajiv Singla. Creation Date: 10/6/2016. + */ +public abstract class BaseAnalyticsCommonUnitTest extends BaseDCAEAnalyticsUnitTest { + + + protected TestProcessorContext testProcessorContext = new TestProcessorContext("", true); + + protected TestMessageProcessor1 getTestMessageProcessor1() { + return new TestMessageProcessor1(); + } + protected TestMessageProcessor2 getTestMessageProcessor2() { + return new TestMessageProcessor2(); + } + protected TestEarlyTerminatingProcessor getTestEarlyTerminationProcessor() { + return new TestEarlyTerminatingProcessor(); + } +} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java new file mode 100644 index 0000000..2ed82b6 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java @@ -0,0 +1,96 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + + +/** + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public class GenericMessageChainProcessorTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void testProcessChainWhenProcessChainHasNoEarlyTermination() throws Exception { + + final TestMessageProcessor1 testMessageProcessor1 = getTestMessageProcessor1(); + final TestMessageProcessor2 testMessageProcessor2 = getTestMessageProcessor2(); + final ImmutableList> testMessageChain = + ImmutableList.of(testMessageProcessor1, testMessageProcessor2); + + final TestProcessorContext testProcessorContext = new TestProcessorContext("Hello", true); + + final GenericMessageChainProcessor genericMessageChainProcessor = + new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); + + final TestProcessorContext finalProcessorContext = genericMessageChainProcessor.processChain(); + + final String result = finalProcessorContext.getResult(); + assertThat("Final Result must be Hello World! Again", result, is("Hello World! Again")); + assertThat("TestProcessor1 state is correct", testMessageProcessor1.getProcessingState(), + is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY)); + assertThat("TestProcessor2 state is correct", testMessageProcessor2.getProcessingState(), + is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY)); + } + + + @Test + public void testProcessChainWhenProcessChainEarlyTermination() throws Exception { + + final TestEarlyTerminatingProcessor testEarlyTerminatingProcessor = getTestEarlyTerminationProcessor(); + final ImmutableList> testMessageChain = + ImmutableList.of(testEarlyTerminatingProcessor, getTestMessageProcessor2()); + final TestProcessorContext testProcessorContext = new TestProcessorContext("Hello", true); + + final GenericMessageChainProcessor genericMessageChainProcessor = + new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); + + final TestProcessorContext finalProcessorContext = genericMessageChainProcessor.processChain(); + final String result = finalProcessorContext.getResult(); + assertNull("Final Result must be null", result); + assertThat("TestEarlyTerminatingProcessor state is correct", + testEarlyTerminatingProcessor.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY)); + } + + @Test(expected = MessageProcessingException.class) + public void testProcessChainWhenIncomingMessageContextIsNull() throws Exception { + + final TestEarlyTerminatingProcessor testEarlyTerminatingProcessor = getTestEarlyTerminationProcessor(); + final ImmutableList> testMessageChain = + ImmutableList.of(testEarlyTerminatingProcessor, getTestMessageProcessor2()); + final TestProcessorContext testProcessorContext = null; + + final GenericMessageChainProcessor genericMessageChainProcessor = + new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); + + genericMessageChainProcessor.processChain(); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java new file mode 100644 index 0000000..a015677 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +/** + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public class TestEarlyTerminatingProcessor extends AbstractMessageProcessor { + + @Override + public String getProcessorDescription() { + return "Terminates the chain early"; + } + + @Override + public TestProcessorContext processMessage(TestProcessorContext processorContext) { + setTerminatingProcessingMessage("Terminating early", processorContext); + return processorContext; + } +} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java new file mode 100644 index 0000000..ac29080 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +/** + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public class TestMessageProcessor1 extends AbstractMessageProcessor { + + @Override + public String getProcessorDescription() { + return "Appends \" World!\" to the message string and set it to result string"; + } + + @Override + public TestProcessorContext processMessage(TestProcessorContext processorContext) { + final String message = processorContext.getMessage(); + processorContext.setResult(message + " World!"); + setFinishedProcessingMessage("Finished Appending world", processorContext); + return processorContext; + } +} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java new file mode 100644 index 0000000..a0704db --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +/** + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public class TestMessageProcessor2 extends AbstractMessageProcessor { + + @Override + public String getProcessorDescription() { + return "Appends \" Again\" to the result string"; + } + + @Override + public TestProcessorContext processMessage(TestProcessorContext processorContext) { + final String result = processorContext.getResult(); + processorContext.setResult(result + " Again"); + setFinishedProcessingMessage("Finished Appending again to result", processorContext); + return processorContext; + } +} diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java new file mode 100644 index 0000000..85e8c74 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.common.service.processor; + +import java.util.LinkedList; +import java.util.List; + +/** + * + * @author Rajiv Singla. Creation Date: 11/8/2016. + */ +public class TestProcessorContext implements ProcessorContext { + + private String message; + private boolean continueProcessingFlag; + private String result; + private List> messageProcessors; + + public TestProcessorContext(String message, boolean continueProcessingFlag) { + this.message = message; + this.continueProcessingFlag = continueProcessingFlag; + this.messageProcessors = new LinkedList<>(); + } + + @Override + public String getMessage() { + return message; + } + + @Override + public boolean canProcessingContinue() { + return continueProcessingFlag; + } + + @Override + public void setProcessingContinueFlag(boolean canProcessingContinue) { + this.continueProcessingFlag = canProcessingContinue; + } + + @Override + public List> getMessageProcessors() { + return messageProcessors; + } + + + public void setMessage(String message) { + this.message = message; + } + + public boolean isContinueProcessingFlag() { + return continueProcessingFlag; + } + + public void setContinueProcessingFlag(boolean continueProcessingFlag) { + this.continueProcessingFlag = continueProcessingFlag; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + +} diff --git a/dcae-analytics-dmaap/pom.xml b/dcae-analytics-dmaap/pom.xml index ce54088..94d84cf 100644 --- a/dcae-analytics-dmaap/pom.xml +++ b/dcae-analytics-dmaap/pom.xml @@ -28,7 +28,7 @@ 4.0.0 - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics 1.0-SNAPSHOT ../pom.xml @@ -52,7 +52,7 @@ - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics-common 1.0-SNAPSHOT @@ -98,7 +98,7 @@ - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics-test 1.0-SNAPSHOT test diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactory.java deleted file mode 100644 index 6966a46..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactory.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.dmaap.module.AnalyticsDMaaPModule; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherFactory; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriberFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nonnull; - -/** - * Creates pre injected implementations for {@link DMaaPMRPublisher} and {@link DMaaPMRSubscriber} - *

- * Usage: - *

Create an instance of DMaaP MR Factory

- *
- *        DMaaPFactory dmaapFactory = DMaaPFactory.initalize()
- *     
- *

Create a new DMaaP MR Publisher

- *
- *         DMaaPMRPublisher publisher = dmaapFactory.createPublisher(publisherConfig)
- *     
- *

Create new DMaaP MR Subscriber

- *
- *         DMaaPMRSubscriber subscriber = dmaapFactory.createSubscriber(subscriberConfig)
- *     
- *

- * All Clients must use this Factory to initalize DMaaP Message Router Publishers and Subscribers - *

- *

- * @author Rajiv Singla. Creation Date: 10/20/2016. - */ -public class DMaaPMRFactory { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRFactory.class); - - private final Injector injector; - - public DMaaPMRFactory(AbstractModule guiceModule) { - injector = Guice.createInjector(guiceModule); - } - - /** - * Returns configured instance of {@link DMaaPMRPublisher} - * - * @param publisherConfig Publisher Config - * @return configured instance of DMaaP MR Publisher - */ - public DMaaPMRPublisher createPublisher(@Nonnull DMaaPMRPublisherConfig publisherConfig) { - final DMaaPMRPublisherFactory publisherFactory = injector.getInstance(DMaaPMRPublisherFactory.class); - LOG.debug("Creating new DMaaP MR Publisher Instance with configuration: {}", publisherConfig); - final DMaaPMRPublisher dMaaPMRPublisher = publisherFactory.create(publisherConfig); - LOG.info("Created new DMaaP MR Publisher Instance. Publisher creation time: {}", - dMaaPMRPublisher.getPublisherCreationTime()); - return dMaaPMRPublisher; - } - - /** - * Returns configured instance of {@link DMaaPMRSubscriber} - * - * @param subscriberConfig Subscriber Config - * @return configured instance of DMaaP MR Subscriber - */ - public DMaaPMRSubscriber createSubscriber(@Nonnull DMaaPMRSubscriberConfig subscriberConfig) { - final DMaaPMRSubscriberFactory subscriberFactory = injector.getInstance(DMaaPMRSubscriberFactory.class); - LOG.debug("Creating new DMaaP MR Subscriber Instance with configuration: {}", subscriberConfig); - final DMaaPMRSubscriber dMaaPMRSubscriber = subscriberFactory.create(subscriberConfig); - LOG.info("Created new DMaaP MR Subscriber Instance. Subscriber creation time: {}", - dMaaPMRSubscriber.getSubscriberCreationTime()); - return dMaaPMRSubscriber; - } - - /** - * Creates an instance of {@link DMaaPMRFactory} - * - * @return {@link DMaaPMRFactory} factory instance - */ - public static DMaaPMRFactory create() { - final DMaaPMRFactory dMaaPMRFactory = new DMaaPMRFactory(new AnalyticsDMaaPModule()); - LOG.info("Created new instance of DMaaP MR Factory"); - return dMaaPMRFactory; - } - - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java deleted file mode 100644 index f2435f1..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.config; - -import com.google.common.base.Objects; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Locale; - -import static org.openecomp.dcae.analytics.common.utils.HTTPUtils.JSON_APPLICATION_TYPE; - -/** - *

- * Contains common parameters for both DMaaP Message Router Publisher and Subscriber Configs - *

- * @author Rajiv Singla. Creation Date: 10/12/2016. - */ -public abstract class DMaaPMRBaseConfig implements DMaaPMRConfig { - - protected static final Logger LOG = LoggerFactory.getLogger(DMaaPMRBaseConfig.class); - - protected String hostName; - protected Integer portNumber; - protected String topicName; - protected String protocol; - protected String userName; - protected String userPassword; - protected String contentType; - - /** - * Provides host name e.g. mrlocal-mtnjftle01.homer.com - * - * @return host name - */ - public String getHostName() { - return hostName; - } - - - /** - * Provides Port Number of DMaaP MR Topic Host. Defaults to 80 - * - * @return host port number - */ - public Integer getPortNumber() { - return portNumber; - } - - /** - * Provides topic name - * - * @return topic name - */ - public String getTopicName() { - return topicName; - } - - /** - * Provides protocol type e.g. http or https - * - * @return protocol type - */ - public String getProtocol() { - return protocol; - } - - /** - * Provides content type e.g. application/json - * - * @return content type - */ - public String getContentType() { - return contentType; - } - - - /** - * Provides User name for the DMaaP MR Topic authentication - * - * @return user name - */ - public String getUserName() { - return userName; - } - - /** - * Provides User password for the DMaaP MR Topic authentication - * - * @return user Password - */ - public String getUserPassword() { - return userPassword; - } - - - /** - * Trims, adjusts casing and validates user input String for protocol selection - * - * @param protocol - User input for protocol String - * @return - network protocol e.g http or https - */ - protected static String normalizeValidateProtocol(final String protocol) { - // validate that only http and https are supported protocols are Supported for DMaaP MR - String normalizedProtocolString = protocol.trim().toLowerCase(Locale.ENGLISH); - if (normalizedProtocolString.isEmpty() || - !(normalizedProtocolString.equals("http") || normalizedProtocolString.equals("https"))) { - - final String errorMessage = - "Unsupported protocol selection. Only HTTPS and HTTPS are currently supported for DMaaP MR"; - - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage)); - } - return normalizedProtocolString; - } - - - /** - * Trims, adjust casing and validates content type is supported by DMaaP. - * - * NOTE: DMaaP currently only support application/json content type - * - * @param contentType content type that needs to checked for DMaaP MR support - * @return true if content type is supported by DMaaP MR - */ - protected static String normalizeValidateContentType(final String contentType) { - // Current DMaaP MR is only supporting "application/json" content type - String normalizedContentType = contentType.trim().toLowerCase(Locale.ENGLISH); - final boolean isSupported = contentType.equals(JSON_APPLICATION_TYPE); - if (!isSupported) { - final String errorMessage = - "Unsupported content type selection. Only application/json is currently supported for DMaaP MR"; - - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage)); - } - return normalizedContentType; - } - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DMaaPMRBaseConfig)) { - return false; - } - DMaaPMRBaseConfig that = (DMaaPMRBaseConfig) o; - return Objects.equal(hostName, that.hostName) && - Objects.equal(portNumber, that.portNumber) && - Objects.equal(topicName, that.topicName) && - Objects.equal(protocol, that.protocol) && - Objects.equal(userName, that.userName) && - Objects.equal(userPassword, that.userPassword) && - Objects.equal(contentType, that.contentType); - } - - @Override - public int hashCode() { - return Objects.hashCode(hostName, portNumber, topicName, protocol, userName, userPassword, contentType); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("hostName", hostName) - .add("portNumber", portNumber) - .add("topicName", topicName) - .add("protocol", protocol) - .add("userName", userName) - .add("contentType", contentType) - .toString(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRConfig.java deleted file mode 100644 index f5ef71e..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.config; - -/** - *

- * Marker Interface for all DMaaP MR Configs. - * Holds Default configuration parameters for all Configs - *

- * @author Rajiv Singla. Creation Date: 10/12/2016. - */ -public interface DMaaPMRConfig { - - Integer DEFAULT_PORT_NUMBER = 80; // default port number - String DEFAULT_USER_NAME = null; // default to no username - String DEFAULT_USER_PASSWORD = null; // defaults to no userPassword - String DEFAULT_PROTOCOL = "https"; // defaults to using https protocol - String DEFAULT_CONTENT_TYPE = "application/json"; // defaults to json content type - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java deleted file mode 100644 index 4a08cd3..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.config; - -import com.google.common.base.Objects; - -import javax.annotation.Nonnull; - -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE; - -/** - *

- * Immutable DMaaP MR Configuration for DMaaP MR Publisher. - *

- * Use {@link DMaaPMRPublisherConfig.Builder} to construct Subscriber Configuration - *

- *

- * @author Rajiv Singla. Creation Date: 10/12/2016. - */ -public class DMaaPMRPublisherConfig extends DMaaPMRBaseConfig { - - /** - * Publisher batching queue size - */ - private int maxBatchSize; - - /** - * Publisher Recovery Queue Size - */ - private int maxRecoveryQueueSize; - - - private DMaaPMRPublisherConfig(@Nonnull String hostName, - @Nonnull Integer portNumber, - @Nonnull String topicName, - @Nonnull String protocol, - @Nonnull String userName, - @Nonnull String userPassword, - @Nonnull String contentType, - int maxBatchSize, - int maxRecoveryQueueSize) { - this.hostName = hostName; - this.portNumber = portNumber; - this.topicName = topicName; - this.protocol = protocol; - this.userName = userName; - this.userPassword = userPassword; - this.contentType = contentType; - this.maxBatchSize = maxBatchSize; - this.maxRecoveryQueueSize = maxRecoveryQueueSize; - } - - - /** - * Builder to initialize immutable {@link DMaaPMRPublisherConfig} object - */ - public static class Builder { - - private String hostName; - private Integer portNumber; - private String topicName; - private String userName; - private String userPassword; - private String protocol; - private String contentType; - private int maxBatchSize; - private int maxRecoveryQueueSize; - - public Builder(@Nonnull String hostName, @Nonnull String topicName) { - // required values - this.hostName = hostName; - this.topicName = topicName; - // Default values - this.portNumber = DEFAULT_PORT_NUMBER; - this.userName = DEFAULT_USER_NAME; - this.userPassword = DEFAULT_USER_PASSWORD; - this.protocol = DEFAULT_PROTOCOL; - this.contentType = DEFAULT_CONTENT_TYPE; - this.maxBatchSize = DEFAULT_PUBLISHER_MAX_BATCH_SIZE; - this.maxRecoveryQueueSize = DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE; - } - - /** - * Setup for custom host port number - Defaults to 80. - * - * @param portNumber custom port number - * @return Builder object itself for chaining - */ - public Builder setPortNumber(@Nonnull Integer portNumber) { - this.portNumber = portNumber; - return this; - } - - - /** - * Setup user name for authentication. If no username is provided authentication will be disabled - * - * @param userName user name for DMaaP Topic Authentication - * @return Builder object itself for chaining - */ - public Builder setUserName(@Nonnull String userName) { - this.userName = userName; - return this; - } - - - /** - * Setup user password for authentication. If no password is provided authentication will be disabled - * - * @param userPassword user password for DMaaP Topic Authentication - * @return Builder object itself for chaining - */ - public Builder setUserPassword(@Nonnull String userPassword) { - this.userPassword = userPassword; - return this; - } - - - /** - * Setup custom Publisher protocol - Defaults to https. - * Note: Only http and https are currently supported. - * - * @param protocol protocol e.g. https - * @return Builder object itself for chaining - */ - public Builder setProtocol(@Nonnull String protocol) { - this.protocol = normalizeValidateProtocol(protocol); - return this; - } - - - /** - * Setup custom Publisher content-type - Defaults to application/json - * - * @param contentType content type e.g. application/json - * @return Builder object itself for chaining - */ - public Builder setContentType(@Nonnull String contentType) { - final String normalizedContentType = normalizeValidateContentType(contentType); - this.contentType = normalizedContentType; - return this; - } - - - /** - * Setup custom Publisher Max Batch Size - Defaults to 100 - * - * @param maxBatchSize max Batch Size - * @return Builder object itself for chaining - */ - public Builder setMaxBatchSize(int maxBatchSize) { - this.maxBatchSize = maxBatchSize; - return this; - } - - - /** - * Setup custom Maximum Recovery Queue Size. Recovery Queue is used to hold messages temporarily in case - * DMaaP MR Publisher topic is not responding for any reason. Defaults to 100,000 - * - * @param maxRecoveryQueueSize max recovery queue size - * @return Builder object itself for chaining - */ - public Builder setMaxRecoveryQueueSize(int maxRecoveryQueueSize) { - this.maxRecoveryQueueSize = maxRecoveryQueueSize; - return this; - } - - /** - * Creates immutable instance of {@link DMaaPMRPublisherConfig} - * - * @return Builds and returns thread safe, immutable {@link DMaaPMRPublisherConfig} object - */ - public DMaaPMRPublisherConfig build() { - return new DMaaPMRPublisherConfig(hostName, portNumber, topicName, protocol, userName, userPassword, - contentType, maxBatchSize, maxRecoveryQueueSize); - } - - } - - - /** - * Returns max Publisher Batch Queue Size - * - * @return max Publisher Batch Queue size - */ - public int getMaxBatchSize() { - return maxBatchSize; - } - - /** - * Returns max Publisher Recovery Queue Size - * - * @return max Recovery Queue size - */ - public int getMaxRecoveryQueueSize() { - return maxRecoveryQueueSize; - } - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - if (!super.equals(o)) { - return false; - } - DMaaPMRPublisherConfig that = (DMaaPMRPublisherConfig) o; - return maxBatchSize == that.maxBatchSize && - maxRecoveryQueueSize == that.maxRecoveryQueueSize; - } - - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), maxBatchSize, maxRecoveryQueueSize); - } - - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("baseConfig", super.toString()) - .add("maxBatchSize", maxBatchSize) - .add("maxRecoveryQueueSize", maxRecoveryQueueSize) - .toString(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java deleted file mode 100644 index 9741fa5..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.config; - -import com.google.common.base.Objects; - -import java.util.UUID; - -import javax.annotation.Nonnull; - -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_GROUP_PREFIX; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_MESSAGE_LIMIT; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_TIMEOUT_MS; - -/** - *

- * Immutable DMaaP MR Configuration for Subscriber. - *

- * Use {@link DMaaPMRSubscriberConfig.Builder} to construct Subscriber Configuration - *

- * - * @author Rajiv Singla. Creation Date: 10/12/2016. - */ -public final class DMaaPMRSubscriberConfig extends DMaaPMRBaseConfig { - - private final String consumerId; - private final String consumerGroup; - private final Integer timeoutMS; - private final Integer messageLimit; - - private DMaaPMRSubscriberConfig(@Nonnull String hostName, - @Nonnull Integer portNumber, - @Nonnull String topicName, - @Nonnull String protocol, - @Nonnull String userName, - @Nonnull String userPassword, - @Nonnull String contentType, - @Nonnull String consumerId, - @Nonnull String consumerGroup, - @Nonnull Integer timeoutMS, - @Nonnull Integer messageLimit) { - this.hostName = hostName; - this.portNumber = portNumber; - this.topicName = topicName; - this.protocol = protocol; - this.userName = userName; - this.userPassword = userPassword; - this.contentType = contentType; - this.consumerId = consumerId; - this.consumerGroup = consumerGroup; - this.timeoutMS = timeoutMS; - this.messageLimit = messageLimit; - } - - /** - * Builder to initialize immutable {@link DMaaPMRSubscriberConfig} object - */ - public static class Builder { - - private String hostName; - private Integer portNumber; - private String topicName; - private String userName; - private String userPassword; - private String protocol; - private String contentType; - private String consumerId; - private String consumerGroup; - private Integer timeoutMS; - private Integer messageLimit; - - public Builder(@Nonnull String hostName, - @Nonnull String topicName) { - // Required Values - this.hostName = hostName; - this.topicName = topicName; - - // Default values - this.portNumber = DEFAULT_PORT_NUMBER; - this.userName = DEFAULT_USER_NAME; - this.userPassword = DEFAULT_USER_PASSWORD; - this.protocol = DEFAULT_PROTOCOL; - this.contentType = DEFAULT_CONTENT_TYPE; - this.consumerId = UUID.randomUUID().toString(); // consumer is assigned a random id by default - this.consumerGroup = DEFAULT_SUBSCRIBER_GROUP_PREFIX + consumerId; // random group is assigned - this.timeoutMS = DEFAULT_SUBSCRIBER_TIMEOUT_MS; // defaults to 10ms timeout - this.messageLimit = DEFAULT_SUBSCRIBER_MESSAGE_LIMIT; // defaults to 1000 message limit - } - - - /** - * Setup for custom host port number - Defaults to 80. - * - * @param portNumber custom port number - * @return Builder object itself for chaining - */ - public Builder setPortNumber(@Nonnull Integer portNumber) { - this.portNumber = portNumber; - return this; - } - - - /** - * Setup user name for authentication. If no username is provided authentication will be disabled - * - * @param userName user name for DMaaP Topic Authentication - * @return Builder object itself for chaining - */ - public Builder setUserName(@Nonnull String userName) { - this.userName = userName; - return this; - } - - - /** - * Setup user password for authentication. If no password is provided authentication will be disabled - * - * @param userPassword user password for DMaaP Topic Authentication - * @return Builder object itself for chaining - */ - public Builder setUserPassword(@Nonnull String userPassword) { - this.userPassword = userPassword; - return this; - } - - - /** - * Setup custom Subscriber protocol - Defaults to https. - * Note: Only http and https are currently supported. - * - * @param protocol protocol e.g. https or http - * @return Builder object itself for chaining - */ - public Builder setProtocol(@Nonnull String protocol) { - - this.protocol = normalizeValidateProtocol(protocol); - return this; - } - - /** - * Setup custom Subscriber content-type - Defaults to application/json - * - * @param contentType content type e.g. application/json - * @return Builder object itself for chaining - */ - public Builder setContentType(@Nonnull String contentType) { - final String normalizedContentType = normalizeValidateContentType(contentType); - this.contentType = normalizedContentType; - return this; - } - - - /** - * Setup custom Consumer Id - Defaults to random Id - * - * @param consumerId - custom consumer ID - * @return Builder object itself for chaining - */ - public Builder setConsumerId(@Nonnull String consumerId) { - this.consumerId = consumerId; - return this; - } - - /** - * Setup custom Consumer Group - Default to OpenDCAE-DMaaPSub-ConsumerID - * - * @param consumerGroup - custom Consumer Group - * @return Builder object itself for chaining - */ - public Builder setConsumerGroup(@Nonnull String consumerGroup) { - this.consumerGroup = consumerGroup; - return this; - } - - /** - * Setup Custom Subscriber timeout in ms - Default to no timeout limit - * - * @param timeoutMS timeout in milliseconds - * @return Builder object itself for chaining - */ - public Builder setTimeoutMS(@Nonnull Integer timeoutMS) { - this.timeoutMS = timeoutMS; - return this; - } - - /** - * Setup custom Subscriber Message Limit - Default to no limit - * - * @param messageLimit message Limit - * @return Builder object itself for chaining - */ - public Builder setMessageLimit(@Nonnull Integer messageLimit) { - this.messageLimit = messageLimit; - return this; - } - - /** - * Builds Immutable instance of {@link DMaaPMRSubscriberConfig} - * - * @return immutable DMaaP Subscriber Config Object - */ - public DMaaPMRSubscriberConfig build() { - return new DMaaPMRSubscriberConfig(hostName, portNumber, topicName, protocol, userName, userPassword, - contentType, consumerId, consumerGroup, timeoutMS, messageLimit); - } - - } - - - /** - * DMaaP MR Subscriber Consumer Id - * - * @return consumer Id - */ - public String getConsumerId() { - return consumerId; - } - - /** - * DMaaP MR Subscriber Consumer Group - * - * @return consumer group - */ - public String getConsumerGroup() { - return consumerGroup; - } - - /** - * DMaaP MR Subscriber Timeout in ms - * - * @return subscriber timeout ms - */ - public Integer getTimeoutMS() { - return timeoutMS; - } - - /** - * DMaaP MR Subscriber message limit - * - * @return subscriber message limit - */ - public Integer getMessageLimit() { - return messageLimit; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - if (!super.equals(o)) { - return false; - } - DMaaPMRSubscriberConfig that = (DMaaPMRSubscriberConfig) o; - return Objects.equal(consumerId, that.consumerId) && - Objects.equal(consumerGroup, that.consumerGroup) && - Objects.equal(timeoutMS, that.timeoutMS) && - Objects.equal(messageLimit, that.messageLimit); - } - - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), consumerId, consumerGroup, timeoutMS, messageLimit); - } - - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("baseConfig", super.toString()) - .add("consumerId", consumerId) - .add("consumerGroup", consumerGroup) - .add("timeoutMS", timeoutMS) - .add("messageLimit", messageLimit) - .toString(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java deleted file mode 100644 index ad6a86f..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.response; - -/** - *

- * Contract for all DMaaPMR Publisher Response - *

- * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public interface DMaaPMRPublisherResponse extends DMaaPMRResponse { - - - /** - * Gets number of pending messages - * - * @return pending messages in the batch queue - */ - int getPendingMessagesCount(); -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java deleted file mode 100644 index dd1dfe8..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.response; - -import com.google.common.base.Objects; - -import javax.annotation.Nonnull; - -/** - *

- * An simple implementation of {@link DMaaPMRPublisherResponse} - *

- * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public class DMaaPMRPublisherResponseImpl implements DMaaPMRPublisherResponse { - - private final Integer responseCode; - private final String responseMessage; - private final int pendingMessagesCount; - - public DMaaPMRPublisherResponseImpl(@Nonnull Integer responseCode, - @Nonnull String responseMessage, - int pendingMessagesCount) { - this.responseCode = responseCode; - this.responseMessage = responseMessage; - this.pendingMessagesCount = pendingMessagesCount; - } - - @Override - public Integer getResponseCode() { - return responseCode; - } - - @Override - public String getResponseMessage() { - return responseMessage; - } - - @Override - public int getPendingMessagesCount() { - return pendingMessagesCount; - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("responseCode", responseCode) - .add("responseMessage", responseMessage) - .add("pendingMessagesCount", pendingMessagesCount) - .toString(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRResponse.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRResponse.java deleted file mode 100644 index 7dc7523..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRResponse.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.response; - -/** - *

- * Contract for DMaaP MR Responses - *

- * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public interface DMaaPMRResponse { - - /** - * Gets HTTP Response Code - * - * @return HTTP Response code as String - */ - Integer getResponseCode(); - - /** - * Gets Response Message - * - * @return Response Message - */ - String getResponseMessage(); - - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java deleted file mode 100644 index fd1a9e3..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.response; - -import java.util.List; - -/** - *

- * Contract for all DMaaP MR Subscriber Responses - *

- * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public interface DMaaPMRSubscriberResponse extends DMaaPMRResponse { - - /** - * Returns message fetched from DMaaP MR Topic - * - * @return collection of actual message retrieved from DMaaP MR Topic - */ - List getFetchedMessages(); - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java deleted file mode 100644 index 1254654..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.response; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableList; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static java.util.Collections.unmodifiableList; - -/** - *

- * A simple implementation for {@link DMaaPMRSubscriberResponse} - *

- * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public class DMaaPMRSubscriberResponseImpl implements DMaaPMRSubscriberResponse { - - private final Integer responseCode; - private final String responseMessage; - private final List fetchedMessages; - - public DMaaPMRSubscriberResponseImpl(@Nonnull Integer responseCode, - @Nonnull String responseMessage, - @Nullable List fetchedMessages) { - this.responseCode = responseCode; - this.responseMessage = responseMessage; - this.fetchedMessages = fetchedMessages != null ? fetchedMessages : ImmutableList.of(); - } - - public DMaaPMRSubscriberResponseImpl(Integer responseCode, String responseMessage) { - this(responseCode, responseMessage, null); - } - - @Override - public Integer getResponseCode() { - return responseCode; - } - - @Override - public String getResponseMessage() { - return responseMessage; - } - - @Override - public List getFetchedMessages() { - return unmodifiableList(fetchedMessages); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("responseCode", responseCode) - .add("responseMessage", responseMessage) - .add("fetchedMessages(size)", fetchedMessages.size()) - .toString(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPModule.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPModule.java deleted file mode 100644 index 1296798..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPModule.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.module; - -import com.google.inject.AbstractModule; -import com.google.inject.assistedinject.FactoryModuleBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherFactory; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherImpl; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueFactory; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueImpl; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriberFactory; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriberImpl; - -/** - * Guice Module to wire concrete implementations with interfaces - *

- * @author Rajiv Singla. Creation Date: 10/20/2016. - */ -public class AnalyticsDMaaPModule extends AbstractModule { - - - @Override - protected void configure() { - - // Bind Http Client - bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault()); - - // Bind Publishing queue - install(new FactoryModuleBuilder().implement(DMaaPMRPublisherQueue.class, DMaaPMRPublisherQueueImpl.class) - .build(DMaaPMRPublisherQueueFactory.class)); - - install(new FactoryModuleBuilder().implement(DMaaPMRPublisher.class, DMaaPMRPublisherImpl.class) - .build(DMaaPMRPublisherFactory.class)); - - install(new FactoryModuleBuilder().implement(DMaaPMRSubscriber.class, DMaaPMRSubscriberImpl.class) - .build(DMaaPMRSubscriberFactory.class)); - - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponent.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponent.java deleted file mode 100644 index e7e8ea4..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponent.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Optional; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang3.StringEscapeUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.util.EntityUtils; -import org.openecomp.dcae.analytics.common.AnalyticsConstants; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.common.utils.HTTPUtils; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponseImpl; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponseImpl; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.util.LinkedList; -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static java.lang.String.format; - -/** - * Base class for DMaaP MR Publishers and Subscriber Implementations containing various utility methods - * - * @author Rajiv Singla. Creation Date: 11/1/2016. - */ -public abstract class BaseDMaaPMRComponent implements DMaaPMRComponent { - - private static final Logger LOG = LoggerFactory.getLogger(BaseDMaaPMRComponent.class); - - private static final ObjectMapper objectMapper = new ObjectMapper(); - - /** - * Creates Base64 encoded Auth Header for given userName and Password - * If either user name of password are null return absent - * - * @param userName username - * @param userPassword user password - * @return base64 encoded auth header if username or password are both non null - */ - protected static Optional getAuthHeader(final @Nullable String userName, - final @Nullable String userPassword) { - if (userName == null || userPassword == null) { - return Optional.absent(); - } else { - final String auth = userName + ":" + userPassword; - final Charset isoCharset = Charset.forName("ISO-8859-1"); - byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(isoCharset)); - return Optional.of("Basic " + new String(encodedAuth, isoCharset)); - } - } - - - /** - * Creates Publisher URI for given {@link DMaaPMRPublisherConfig} - * - * @param publisherConfig publisher settings - * - * @return DMaaP MR Publisher Topic URI that can be used to post messages to MR Topic - */ - protected static URI createPublisherURI(final DMaaPMRPublisherConfig publisherConfig) { - final String hostName = publisherConfig.getHostName(); - final Integer portNumber = publisherConfig.getPortNumber(); - final String getProtocol = publisherConfig.getProtocol(); - final String topicName = publisherConfig.getTopicName(); - URI publisherURI = null; - try { - publisherURI = new URIBuilder().setScheme(getProtocol).setHost(hostName).setPort(portNumber) - .setPath(AnalyticsConstants.DMAAP_URI_PATH_PREFIX + topicName).build(); - } catch (URISyntaxException e) { - final String errorMessage = format("Error while creating publisher URI: %s", e); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - LOG.info("Created DMaaP MR Publisher URI: {}", publisherURI); - return publisherURI; - } - - - /** - * Creates Subscriber URI for given {@link DMaaPMRSubscriberConfig} - * - * @param subscriberConfig subscriber settings - * - * @return DMaaP MR Subscriber Topic URI that can be used to fetch messages from MR topic - */ - protected static URI createSubscriberURI(final DMaaPMRSubscriberConfig subscriberConfig) { - final String hostName = subscriberConfig.getHostName(); - final Integer portNumber = subscriberConfig.getPortNumber(); - final String getProtocol = subscriberConfig.getProtocol(); - final String topicName = subscriberConfig.getTopicName(); - final String consumerId = subscriberConfig.getConsumerId(); - final String consumerGroup = subscriberConfig.getConsumerGroup(); - final Integer timeoutMS = subscriberConfig.getTimeoutMS(); - final Integer messageLimit = subscriberConfig.getMessageLimit(); - URI subscriberURI = null; - try { - URIBuilder uriBuilder = new URIBuilder().setScheme(getProtocol).setHost(hostName).setPort(portNumber) - .setPath(AnalyticsConstants.DMAAP_URI_PATH_PREFIX - + topicName + "/" - + consumerGroup + "/" + - consumerId); - // add query params if present - if (timeoutMS > 0) { - uriBuilder.addParameter(AnalyticsConstants.SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME, timeoutMS.toString()); - } - if (messageLimit > 0) { - uriBuilder.addParameter(AnalyticsConstants.SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME, - messageLimit.toString()); - } - subscriberURI = uriBuilder.build(); - - } catch (URISyntaxException e) { - final String errorMessage = format("Error while creating subscriber URI: %s", e); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - - LOG.info("Created DMaaP MR Subscriber URI: {}", subscriberURI); - return subscriberURI; - } - - - /** - * Creates 202 (Accepted) Response code message - * - * @param batchQueueSize batch Queue size - * - * @return response with 202 message code - */ - protected static DMaaPMRPublisherResponse createPublisherAcceptedResponse(int batchQueueSize) { - return createPublisherResponse(HTTPUtils.HTTP_ACCEPTED_RESPONSE_CODE, - "Accepted - Messages queued for batch publishing to MR Topic", batchQueueSize); - } - - - /** - * Creates 204 (No Content) Response code message - * - * @return response with 204 message code - */ - protected static DMaaPMRPublisherResponse createPublisherNoContentResponse() { - return createPublisherResponse(HTTPUtils.HTTP_NO_CONTENT_RESPONSE_CODE, - "No Content - No Messages in batch queue for flushing to MR Topic", 0); - } - - - /** - * Creates Publisher Response for given response code, response Message and pending Message Count - * - * @param responseCode HTTP Status Code - * @param responseMessage response message - * @param pendingMessages pending messages in batch queue - * - * @return DMaaP MR Publisher Response - */ - protected static DMaaPMRPublisherResponse createPublisherResponse(int responseCode, String - responseMessage, int pendingMessages) { - return new DMaaPMRPublisherResponseImpl(responseCode, responseMessage, pendingMessages); - } - - - /** - * Returns weekly consistent pending messages in batch queue - * - * @param publisherQueue batch queue - * @param publisherConfig publisher settings - * - * @return pending messages to be published - */ - protected static int getPendingMessages(final @Nonnull DMaaPMRPublisherQueue publisherQueue, - final @Nonnull DMaaPMRPublisherConfig publisherConfig) { - return publisherConfig.getMaxBatchSize() - publisherQueue.getBatchQueueRemainingSize(); - } - - - /** - * Creates Subscriber Response for give response Code, response Message and fetch messages - * - * @param responseCode response Code - * @param responseMessage response Message - * @param fetchedMessages fetched messages - * - * @return DMaaP MR Subscriber Response - */ - protected static DMaaPMRSubscriberResponse createSubscriberResponse(int responseCode, String - responseMessage, List fetchedMessages) { - if (fetchedMessages == null) { - return new DMaaPMRSubscriberResponseImpl(responseCode, responseMessage); - } else { - return new DMaaPMRSubscriberResponseImpl(responseCode, responseMessage, fetchedMessages); - } - } - - - /** - * Custom response handler which extract status code and response body - * - * @return Pair containing Response code and response body - */ - protected static ResponseHandler> responseHandler() { - return new ResponseHandler>() { - @Override - public Pair handleResponse(HttpResponse response) throws IOException { - // Get Response status code - final int status = response.getStatusLine().getStatusCode(); - final HttpEntity responseEntity = response.getEntity(); - // If response entity is not null - extract response body as string - String responseEntityString = ""; - if (responseEntity != null) { - responseEntityString = EntityUtils.toString(responseEntity); - } - return new ImmutablePair<>(status, responseEntityString); - } - }; - } - - - /** - * Adds message to Publisher recovery queue. If recovery queue is full throws an error as messages will - * be lost - * - * @param publisherQueue publisher queue - * @param messages recoverable messages to be published to recovery queue - */ - protected static void addMessagesToRecoveryQueue(DMaaPMRPublisherQueue publisherQueue, - List messages) { - try { - publisherQueue.addRecoverableMessages(messages); - - LOG.debug("Messages Added to Recovery Queue. Messages Size: {}, Recovery Queue Remaining Size: {}", - messages.size(), publisherQueue.getBatchQueueRemainingSize()); - - } catch (IllegalStateException e) { - final String errorMessage = format("Unable to put messages in recovery queue. Messages will be lost. " + - "Recovery Queue might be full. Message Size: %d, Recovery Queue Remaining Capacity: %d", - messages.size(), publisherQueue.getRecoveryQueueRemainingSize()); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - } - - - /** - * Converts List of messages to Json String Array which can be published to DMaaP MR topic. - * - * @param messages messages that need to parsed to Json Array representation - * @return json string representation of message - */ - protected static String convertToJsonString(final @Nullable List messages) { - // If messages are null or empty just return empty array - if (messages == null || messages.size() == 0) { - return "[]"; - } - - - List jsonMessageObjectsList = new LinkedList<>(); - - try { - for (String message : messages) { - final JsonNode jsonNode = objectMapper.readTree(message); - jsonMessageObjectsList.add(jsonNode); - } - return objectMapper.writeValueAsString(jsonMessageObjectsList); - } catch (JsonProcessingException e) { - final String errorMessage = - format("Unable to convert publisher messages to Json. Messages: %s, Json Error: %s", - messages, e); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - - } catch (IOException e) { - final String errorMessage = - format("IO Exception while converting publisher messages to Json. Messages: %s, Json Error: %s", - messages, e); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - } - - - /** - * Converts subscriber messages json string to List of messages. If message Json String is empty - * or null - * - * @param messagesJsonString json messages String - * - * @return List containing DMaaP MR Messages - */ - protected static List convertJsonToStringMessages(final @Nullable String messagesJsonString) { - - final LinkedList messages = new LinkedList<>(); - - // If message string is not null or not empty parse json message array to List of string messages - if (!(messagesJsonString == null) && !messagesJsonString.trim().isEmpty() - && !messagesJsonString.trim().equals("[]")) { - - try { - final List messageList = objectMapper.readValue(messagesJsonString, List.class); - for (Object message : messageList) { - final String jsonMessageString = objectMapper.writeValueAsString(message); - if (jsonMessageString.startsWith("\"") && jsonMessageString.endsWith("\"")) { - final String jsonSubString = jsonMessageString.substring(1, jsonMessageString.length() - 1); - messages.add(StringEscapeUtils.unescapeJson(jsonSubString)); - } else { - messages.add(StringEscapeUtils.unescapeJson(jsonMessageString)); - } - } - - } catch (IOException e) { - final String errorMessage = - format("Unable to convert subscriber Json String to Messages. Subscriber Response String: %s," + - " Json Error: %s", messagesJsonString, e); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - - } - return messages; - } - - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/DMaaPMRComponent.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/DMaaPMRComponent.java deleted file mode 100644 index 6f9a0ce..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/DMaaPMRComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service; - -/** - * Marker interface for all DMaaP MR Components e.g. MR Publishers, MR Subscribers - * - * @author Rajiv Singla. Creation Date: 11/1/2016. - */ -public interface DMaaPMRComponent { -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisher.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisher.java deleted file mode 100644 index afbdf9f..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisher.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; - -import java.util.Date; -import java.util.List; - -/** - *

- * DMaaP MR Publisher can be used to publish messages to DMaaP MR Topics. - *

- * - * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public interface DMaaPMRPublisher extends AutoCloseable { - - - /** - *

- * Adds collection of messages to DMaaP MR Topic Publishing Queue. - *

- * Note: Invoking this method may or may not cause publishing immediately - * as publishing in done is batch mode by default. Parameter maxBatchSize - * in {@link DMaaPMRPublisherConfig} is used to determine max batch queue size. - * If the maxBatchSize is reached all message will be published automatically - * during subsequent call. - *

- * - * @param messages messages to publish to DMaaP MR Publisher - * @return response which may contain Http Response code 202 (Accepted) as publishing - * will proceed when max batch size is reached - * - * @throws DCAEAnalyticsRuntimeException DCAEAnalyticsRuntimeException - */ - DMaaPMRPublisherResponse publish(List messages) throws DCAEAnalyticsRuntimeException; - - - /** - *

- * Forces publishing of messages to DMaaP MR Topic and returns {@link DMaaPMRPublisherResponse} - * which can be inspected for HTTP status code of publishing call to DMaaP MR Topic. - *

- * - * @param messages messages to publish to DMaaP MR Publisher - * @return DMaaP Message Router Publisher Response - * - * @throws DCAEAnalyticsRuntimeException DCAEAnalyticsRuntimeException - */ - DMaaPMRPublisherResponse forcePublish(List messages) throws DCAEAnalyticsRuntimeException; - - - /** - *

- * Forces publishing of messages in Publisher queue to DMaaP MR Topic and returns - * {@link DMaaPMRPublisherResponse}.If there are no messages were in the queue to - * be flushed response code 304 (Not Modified) will be returned - *

- * - * @return DMaaP Message Router Publisher Response - */ - DMaaPMRPublisherResponse flush(); - - - /** - *

- * Returns the creation time when Publisher instance was created. - *

- * - * @return creation time of Subscriber instance - */ - Date getPublisherCreationTime(); - - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java deleted file mode 100644 index 74245f8..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import org.openecomp.dcae.analytics.dmaap.DMaaPMRFactory; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; - -/** - *

- * Factory to initialize instance of {@link DMaaPMRPublisher} for Guice DI injection purposes. - *

- * - * NOTE: Client should not use this Factory to initialize {@link DMaaPMRPublisher} unless they - * are wiring dependencies using Guice. Client must use {@link DMaaPMRFactory} to initialize - * guice injected Publisher instances - * - *

- * @author Rajiv Singla. Creation Date: 10/20/2016. - */ -public interface DMaaPMRPublisherFactory { - - DMaaPMRPublisher create(DMaaPMRPublisherConfig publisherConfig); - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java deleted file mode 100644 index 425bead..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.http.HttpHeaders; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.openecomp.dcae.analytics.common.AnalyticsConstants; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.service.BaseDMaaPMRComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URI; -import java.util.Date; -import java.util.List; - -import static org.openecomp.dcae.analytics.common.utils.HTTPUtils.isSuccessfulResponseCode; -import static java.lang.String.format; - -/** - * Concrete Implementation of {@link DMaaPMRPublisher} which uses {@link HttpClient} - * - * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPMRPublisher { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRPublisherImpl.class); - - private final DMaaPMRPublisherConfig publisherConfig; - private final CloseableHttpClient closeableHttpClient; - private final DMaaPMRPublisherQueue publisherQueue; - private final Date publisherCreationTime; - private URI publisherUri; - - @Inject - public DMaaPMRPublisherImpl(@Assisted DMaaPMRPublisherConfig publisherConfig, - DMaaPMRPublisherQueueFactory dMaaPMRPublisherQueueFactory, - CloseableHttpClient closeableHttpClient) { - - this.publisherConfig = publisherConfig; - this.publisherQueue = dMaaPMRPublisherQueueFactory.create( - publisherConfig.getMaxBatchSize(), publisherConfig.getMaxRecoveryQueueSize()); - this.closeableHttpClient = closeableHttpClient; - this.publisherUri = createPublisherURI(publisherConfig); - this.publisherCreationTime = new Date(); - } - - - @Override - public DMaaPMRPublisherResponse publish(List messages) throws DCAEAnalyticsRuntimeException { - - final int batchQueueRemainingSize = publisherQueue.getBatchQueueRemainingSize(); - - // if messages size is less than batch queue size - just queue them for batch publishing - if (batchQueueRemainingSize > messages.size()) { - LOG.debug("Adding messages to batch Queue. No flushing required. Messages Size:{}. Batch Queue Size:{}", - messages.size(), batchQueueRemainingSize); - final int batchQueueSize = publisherQueue.addBatchMessages(messages); - return createPublisherAcceptedResponse(batchQueueSize); - - } else { - - // grab all already queued messages, append current messages and force publish them to DMaaP MR topic - final List queueMessages = publisherQueue.getMessageForPublishing(); - LOG.debug("Batch Queue capacity exceeds messages size. Flushing of all pending messages to DMaaP MR " + - "Publisher Topic."); - final DMaaPMRPublisherResponse forcePublishResponse = - forcePublish(Lists.newLinkedList(Iterables.concat(queueMessages, messages))); - return forcePublishResponse; - } - - } - - @Override - public DMaaPMRPublisherResponse forcePublish(List messages) throws DCAEAnalyticsRuntimeException { - - LOG.debug("Force publishing messages to DMaaP MR Topic. Messages Size: {}", messages.size()); - - final String contentType = publisherConfig.getContentType(); - final String userName = publisherConfig.getUserName(); - final String userPassword = publisherConfig.getUserPassword(); - final HttpPost postRequest = new HttpPost(publisherUri); - - // add Authorization Header if username and password are present - final Optional authHeader = getAuthHeader(userName, userPassword); - if (authHeader.isPresent()) { - postRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader.get()); - } else { - LOG.debug("DMaaP MR Publisher Authentication is disabled as username or password is not present."); - } - - // Create post string entity - final String messagesJson = convertToJsonString(messages); - final StringEntity requestEntity = - new StringEntity(messagesJson, ContentType.create(contentType, "UTF-8")); - postRequest.setEntity(requestEntity); - - try { - final Pair responsePair = closeableHttpClient.execute(postRequest, responseHandler()); - final Integer responseCode = responsePair.getLeft(); - final String responseBody = responsePair.getRight(); - // if messages were published successfully, return successful response - if (isSuccessfulResponseCode(responseCode)) { - LOG.debug("DMaaP MR Messages published successfully. DMaaP Response Code: {}. DMaaP Response " + - "Body: {}, Number of Messages published: {}", - responseCode, responseBody, messages.size()); - - } else { - LOG.warn("Unable to publish messages to DMaaP MR Topic. DMaaP Response Code: {}, DMaaP Response " + - "Body: {}. Messages will be queued in recovery queue", responseCode, responseBody); - addMessagesToRecoveryQueue(publisherQueue, messages); - } - - return createPublisherResponse(responseCode, responseBody, - getPendingMessages(publisherQueue, publisherConfig)); - - } catch (IOException e) { - // If IO Error then we need to also put messages in recovery queue - addMessagesToRecoveryQueue(publisherQueue, messages); - final String errorMessage = format("IO Exception while publishing messages to DMaaP Topic. " + - "Messages will be queued in recovery queue. Messages Size: %d", messages.size()); - - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - - } - - - @Override - public DMaaPMRPublisherResponse flush() { - final List queueMessages = publisherQueue.getMessageForPublishing(); - // If there are no message return 204 (No Content) response code - if (queueMessages.size() == 0) { - LOG.debug("No messages to publish to batch queue. Returning 204 status code"); - return createPublisherNoContentResponse(); - } else { - // force publish messages in queue - return forcePublish(queueMessages); - } - } - - @Override - public Date getPublisherCreationTime() { - return new Date(publisherCreationTime.getTime()); - } - - @Override - public void close() throws Exception { - - // flush current message in the queue - int retrialNumber = 0; - int flushResponseCode; - - // automatic retries if messages cannot be flushed - do { - retrialNumber++; - DMaaPMRPublisherResponse flushResponse = flush(); - flushResponseCode = flushResponse.getResponseCode(); - - if (!isSuccessfulResponseCode(flushResponseCode)) { - LOG.warn("Unable to flush batch messages to publisher due to DMaaP MR invalid Response: {}. " + - "Retrial No: {} of Max {} Retries", flushResponseCode, retrialNumber, - AnalyticsConstants.PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE); - - Thread.sleep(AnalyticsConstants.PUBLISHER_DELAY_MS_ON_RETRIES_ON_CLOSE); - } - } while (retrialNumber <= AnalyticsConstants.PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE && - !isSuccessfulResponseCode(flushResponseCode)); - - if (!isSuccessfulResponseCode(flushResponseCode)) { - LOG.error("Unable to flush batch messages to publisher. Messages loss cannot be prevented"); - } else { - LOG.info("Successfully published all batched messages to publisher."); - } - - // close http client - closeableHttpClient.close(); - - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java deleted file mode 100644 index cb3c113..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import java.util.List; - -/** - *

- * DMaaP MR Publisher Queue handles back pressure in case DMaaP MR Publisher topic - * is offline for some reason. It does so by having a recovery queue which keeps - * messages in order in case there is temporary interruption in DMaaP Publisher - *

- * - * @author Rajiv Singla. Creation Date: 11/1/2016. - */ -public interface DMaaPMRPublisherQueue { - - /** - *

- * Add batchMessages to Batch Queue - *

- * - * @param batchMessages messages that needs to be added to batch queue - * @return current size of batch queue - * - * @throws IllegalStateException if batch queue does not have enough space - */ - int addBatchMessages(List batchMessages) throws IllegalStateException; - - - /** - *

- * Add recoverable messages to Recoverable Queue - *

- * - * @param recoverableMessages messages that needs to be added to recoverable queue - * @return current size of the recoverable queue - * - * @throws IllegalStateException if recoverable queue does not have enough space - */ - int addRecoverableMessages(List recoverableMessages) throws IllegalStateException; - - /** - *

- * Get messages that need to be published to DMaaP topic. Messages in recoverable - * queue are appended if present. - *

- * - * @return List of messages from both batch and recovery queue - */ - List getMessageForPublishing(); - - /** - *

- * Remaining capacity of Batch Queue - *

- * - * @return Remaining Batch Queue Size - */ - int getBatchQueueRemainingSize(); - - /** - *

- * Remaining capacity of Recovery Queue - *

- * - * @return Remaining Recovery Queue Size - */ - int getRecoveryQueueRemainingSize(); - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java deleted file mode 100644 index bfc3dab..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import com.google.inject.assistedinject.Assisted; - -/** - *

- * Factory to initialize instance of {@link DMaaPMRPublisherQueue} for Guice DI injection purposes. - *

- * - * @author Rajiv Singla. Creation Date: 11/1/2016. - */ -public interface DMaaPMRPublisherQueueFactory { - - DMaaPMRPublisherQueue create(@Assisted("batchQueueSize") int batchQueueSize, - @Assisted("recoveryQueueSize") int recoveryQueueSize); - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java deleted file mode 100644 index 0367950..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.LinkedBlockingDeque; - -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Lists.newLinkedList; -import static java.util.Collections.unmodifiableList; - -/** - *

- * An implementation of {@link DMaaPMRPublisherQueue} which uses {@link java.util.concurrent.BlockingDeque} - * for batch and recovery queues - *

- * - * - * @author Rajiv Singla. Creation Date: 11/1/2016. - */ -public class DMaaPMRPublisherQueueImpl implements DMaaPMRPublisherQueue { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRPublisherQueueImpl.class); - - private final LinkedBlockingDeque batchQueue; - private final LinkedBlockingDeque recoveryQueue; - - @Inject - public DMaaPMRPublisherQueueImpl(@Assisted("batchQueueSize") int batchQueueSize, - @Assisted("recoveryQueueSize") int recoveryQueueSize) { - batchQueue = new LinkedBlockingDeque<>(batchQueueSize); - recoveryQueue = new LinkedBlockingDeque<>(recoveryQueueSize); - LOG.debug("Creating Instance of DMaaP Publisher Queue. BatchQueueSize: {}, RecoveryQueueSize: {}", - batchQueueSize, recoveryQueueSize); - } - - @Override - public synchronized int addBatchMessages(List batchMessages) throws IllegalStateException { - - // checks if batchMessages size does not exceed batch queue capacity - if (batchMessages.size() > batchQueue.remainingCapacity()) { - throw new IllegalStateException("Not enough capacity to add batchMessages in batch queue"); - } - - // Add batchMessages to batch queue - for (String message : batchMessages) { - batchQueue.add(message); - } - - // returns current elements size in batch queue - return batchQueue.size(); - } - - @Override - public synchronized int addRecoverableMessages(List recoverableMessages) throws IllegalStateException { - - // checks if messages size does not exceed recovery queue size - if (recoverableMessages.size() > recoveryQueue.remainingCapacity()) { - throw new IllegalStateException("Not enough capacity to add messages in recovery queue"); - } - - // add messages to recovery queue - for (String recoverableMessage : recoverableMessages) { - recoveryQueue.add(recoverableMessage); - } - - // returns current size of recovery queue - return recoveryQueue.size(); - } - - @Override - public synchronized List getMessageForPublishing() { - - final List recoveryMessageList = new LinkedList<>(); - final List batchMessagesList = new LinkedList<>(); - - // get messages from recovery queue if present - if (recoveryQueue.size() > 0) { - recoveryQueue.drainTo(recoveryMessageList); - } - - // get messages from batch queue if present - if (batchQueue.size() > 0) { - batchQueue.drainTo(batchMessagesList); - } - - // concat recovery and batch queue elements - return unmodifiableList(newLinkedList(concat(recoveryMessageList, batchMessagesList))); - } - - @Override - public synchronized int getBatchQueueRemainingSize() { - return batchQueue.remainingCapacity(); - } - - @Override - public synchronized int getRecoveryQueueRemainingSize() { - return recoveryQueue.remainingCapacity(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java deleted file mode 100644 index 096c0a9..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.subscriber; - -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; - -import java.util.Date; - -/** - *

- * DMaaP MR Subscriber can be used to subscribe messages from DMaaP MR Topics. - *

- * - * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public interface DMaaPMRSubscriber extends AutoCloseable { - - /** - * Fetches Messages from DMaaP MR Topic. {@link DMaaPMRPublisherConfig} settings parameters - * for messageLimit and message timeout are used - * - * @return DMaaP Message Router Subscriber Response - * - * @throws DCAEAnalyticsRuntimeException DCAE Analytics Exception - */ - DMaaPMRSubscriberResponse fetchMessages() throws DCAEAnalyticsRuntimeException; - - - /** - * Returns the Subscriber instance creation time - *

- * NOTE: Due to DMaaP API Design - Subscribers can only fetch messages which - * are published to the topic after the creation of the Subscriber. - * - * @return creation time of Subscriber instance - */ - Date getSubscriberCreationTime(); - - -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java deleted file mode 100644 index 33c405e..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.subscriber; - -import org.openecomp.dcae.analytics.dmaap.DMaaPMRFactory; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; - -/** - * Factory to initialize instance of {@link DMaaPMRSubscriber} for Guice DI injection purposes. - *

- * - * NOTE: Client should not use this Factory to initialize {@link DMaaPMRSubscriber} unless they - * are wiring dependencies using Guice. Client must use {@link DMaaPMRFactory} to initialize - * guice injected Subscriber instances - * - *

- * @author Rajiv Singla. Creation Date: 10/20/2016. - */ -public interface DMaaPMRSubscriberFactory { - - DMaaPMRSubscriber create(DMaaPMRSubscriberConfig subscriberConfig); -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java deleted file mode 100644 index 6d98189..0000000 --- a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.subscriber; - -import com.google.common.base.Optional; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.http.HttpHeaders; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.analytics.dmaap.service.BaseDMaaPMRComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URI; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import static org.openecomp.dcae.analytics.common.utils.HTTPUtils.isSuccessfulResponseCode; -import static java.lang.String.format; - -/** - * Concrete Implementation of {@link DMaaPMRSubscriber} which uses {@link HttpClient} - * - * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public class DMaaPMRSubscriberImpl extends BaseDMaaPMRComponent implements DMaaPMRSubscriber { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRSubscriberImpl.class); - - private final DMaaPMRSubscriberConfig subscriberConfig; - private final CloseableHttpClient closeableHttpClient; - private final URI subscriberUri; - private final Date subscriberCreationTime; - - @Inject - public DMaaPMRSubscriberImpl(@Assisted DMaaPMRSubscriberConfig subscriberConfig, - CloseableHttpClient closeableHttpClient) { - this.subscriberConfig = subscriberConfig; - this.closeableHttpClient = closeableHttpClient; - this.subscriberUri = createSubscriberURI(subscriberConfig); - this.subscriberCreationTime = new Date(); - } - - @Override - public DMaaPMRSubscriberResponse fetchMessages() throws DCAEAnalyticsRuntimeException { - - final String userName = subscriberConfig.getUserName(); - final String userPassword = subscriberConfig.getUserPassword(); - - final HttpGet getRequest = new HttpGet(subscriberUri); - - // add Authorization Header if username and password are present - final Optional authHeader = getAuthHeader(userName, userPassword); - if (authHeader.isPresent()) { - getRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader.get()); - } else { - LOG.debug("DMaaP MR Subscriber Authentication is disabled as username or password is not present."); - } - - try { - - final Pair responsePair = closeableHttpClient.execute(getRequest, responseHandler()); - final Integer responseCode = responsePair.getLeft(); - final String responseBody = responsePair.getRight(); - - List fetchedMessages = new LinkedList<>(); - String responseMessage = responseBody; - - // if messages were published successfully, return successful response - if (isSuccessfulResponseCode(responseCode)) { - if (responseBody != null) { - fetchedMessages = convertJsonToStringMessages(responseBody); - responseMessage = "Messages Fetched Successfully"; - } else { - responseMessage = "DMaaP Response Body had no messages"; - } - } else { - LOG.error("Unable to fetch messages to DMaaP MR Topic. DMaaP MR unsuccessful Response Code: {}, " + - "DMaaP Response Body: {}", responseCode, responseBody); - } - - return createSubscriberResponse(responseCode, responseMessage, fetchedMessages); - - } catch (IOException e) { - - final String errorMessage = - format("IO Exception while fetching messages from DMaaP Topic. Exception %s", e); - throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); - } - - - } - - @Override - public Date getSubscriberCreationTime() { - return new Date(subscriberCreationTime.getTime()); - } - - @Override - public void close() throws Exception { - closeableHttpClient.close(); - } -} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactory.java new file mode 100644 index 0000000..6a6e064 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactory.java @@ -0,0 +1,112 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.dmaap.module.AnalyticsDMaaPModule; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriberFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; + +/** + * Creates pre injected implementations for {@link DMaaPMRPublisher} and {@link DMaaPMRSubscriber} + *

+ * Usage: + *

Create an instance of DMaaP MR Factory

+ *
+ *        DMaaPFactory dmaapFactory = DMaaPFactory.initalize()
+ *     
+ *

Create a new DMaaP MR Publisher

+ *
+ *         DMaaPMRPublisher publisher = dmaapFactory.createPublisher(publisherConfig)
+ *     
+ *

Create new DMaaP MR Subscriber

+ *
+ *         DMaaPMRSubscriber subscriber = dmaapFactory.createSubscriber(subscriberConfig)
+ *     
+ *

+ * All Clients must use this Factory to initalize DMaaP Message Router Publishers and Subscribers + *

+ *

+ * @author Rajiv Singla. Creation Date: 10/20/2016. + */ +public class DMaaPMRFactory { + + private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRFactory.class); + + private final Injector injector; + + public DMaaPMRFactory(AbstractModule guiceModule) { + injector = Guice.createInjector(guiceModule); + } + + /** + * Returns configured instance of {@link DMaaPMRPublisher} + * + * @param publisherConfig Publisher Config + * @return configured instance of DMaaP MR Publisher + */ + public DMaaPMRPublisher createPublisher(@Nonnull DMaaPMRPublisherConfig publisherConfig) { + final DMaaPMRPublisherFactory publisherFactory = injector.getInstance(DMaaPMRPublisherFactory.class); + LOG.debug("Creating new DMaaP MR Publisher Instance with configuration: {}", publisherConfig); + final DMaaPMRPublisher dMaaPMRPublisher = publisherFactory.create(publisherConfig); + LOG.info("Created new DMaaP MR Publisher Instance. Publisher creation time: {}", + dMaaPMRPublisher.getPublisherCreationTime()); + return dMaaPMRPublisher; + } + + /** + * Returns configured instance of {@link DMaaPMRSubscriber} + * + * @param subscriberConfig Subscriber Config + * @return configured instance of DMaaP MR Subscriber + */ + public DMaaPMRSubscriber createSubscriber(@Nonnull DMaaPMRSubscriberConfig subscriberConfig) { + final DMaaPMRSubscriberFactory subscriberFactory = injector.getInstance(DMaaPMRSubscriberFactory.class); + LOG.debug("Creating new DMaaP MR Subscriber Instance with configuration: {}", subscriberConfig); + final DMaaPMRSubscriber dMaaPMRSubscriber = subscriberFactory.create(subscriberConfig); + LOG.info("Created new DMaaP MR Subscriber Instance. Subscriber creation time: {}", + dMaaPMRSubscriber.getSubscriberCreationTime()); + return dMaaPMRSubscriber; + } + + /** + * Creates an instance of {@link DMaaPMRFactory} + * + * @return {@link DMaaPMRFactory} factory instance + */ + public static DMaaPMRFactory create() { + final DMaaPMRFactory dMaaPMRFactory = new DMaaPMRFactory(new AnalyticsDMaaPModule()); + LOG.info("Created new instance of DMaaP MR Factory"); + return dMaaPMRFactory; + } + + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java new file mode 100644 index 0000000..bb594f8 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRBaseConfig.java @@ -0,0 +1,193 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.config; + +import com.google.common.base.Objects; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Locale; + +import static org.openecomp.dcae.apod.analytics.common.utils.HTTPUtils.JSON_APPLICATION_TYPE; + +/** + *

+ * Contains common parameters for both DMaaP Message Router Publisher and Subscriber Configs + *

+ * @author Rajiv Singla. Creation Date: 10/12/2016. + */ +public abstract class DMaaPMRBaseConfig implements DMaaPMRConfig { + + protected static final Logger LOG = LoggerFactory.getLogger(DMaaPMRBaseConfig.class); + + protected String hostName; + protected Integer portNumber; + protected String topicName; + protected String protocol; + protected String userName; + protected String userPassword; + protected String contentType; + + /** + * Provides host name e.g. mrlocal-mtnjftle01.homer.com + * + * @return host name + */ + public String getHostName() { + return hostName; + } + + + /** + * Provides Port Number of DMaaP MR Topic Host. Defaults to 80 + * + * @return host port number + */ + public Integer getPortNumber() { + return portNumber; + } + + /** + * Provides topic name + * + * @return topic name + */ + public String getTopicName() { + return topicName; + } + + /** + * Provides protocol type e.g. http or https + * + * @return protocol type + */ + public String getProtocol() { + return protocol; + } + + /** + * Provides content type e.g. application/json + * + * @return content type + */ + public String getContentType() { + return contentType; + } + + + /** + * Provides User name for the DMaaP MR Topic authentication + * + * @return user name + */ + public String getUserName() { + return userName; + } + + /** + * Provides User password for the DMaaP MR Topic authentication + * + * @return user Password + */ + public String getUserPassword() { + return userPassword; + } + + + /** + * Trims, adjusts casing and validates user input String for protocol selection + * + * @param protocol - User input for protocol String + * @return - network protocol e.g http or https + */ + protected static String normalizeValidateProtocol(final String protocol) { + // validate that only http and https are supported protocols are Supported for DMaaP MR + String normalizedProtocolString = protocol.trim().toLowerCase(Locale.ENGLISH); + if (normalizedProtocolString.isEmpty() || + !(normalizedProtocolString.equals("http") || normalizedProtocolString.equals("https"))) { + + final String errorMessage = + "Unsupported protocol selection. Only HTTPS and HTTPS are currently supported for DMaaP MR"; + + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage)); + } + return normalizedProtocolString; + } + + + /** + * Trims, adjust casing and validates content type is supported by DMaaP. + * + * NOTE: DMaaP currently only support application/json content type + * + * @param contentType content type that needs to checked for DMaaP MR support + * @return true if content type is supported by DMaaP MR + */ + protected static String normalizeValidateContentType(final String contentType) { + // Current DMaaP MR is only supporting "application/json" content type + String normalizedContentType = contentType.trim().toLowerCase(Locale.ENGLISH); + final boolean isSupported = contentType.equals(JSON_APPLICATION_TYPE); + if (!isSupported) { + final String errorMessage = + "Unsupported content type selection. Only application/json is currently supported for DMaaP MR"; + + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage)); + } + return normalizedContentType; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DMaaPMRBaseConfig)) { + return false; + } + DMaaPMRBaseConfig that = (DMaaPMRBaseConfig) o; + return Objects.equal(hostName, that.hostName) && + Objects.equal(portNumber, that.portNumber) && + Objects.equal(topicName, that.topicName) && + Objects.equal(protocol, that.protocol) && + Objects.equal(userName, that.userName) && + Objects.equal(userPassword, that.userPassword) && + Objects.equal(contentType, that.contentType); + } + + @Override + public int hashCode() { + return Objects.hashCode(hostName, portNumber, topicName, protocol, userName, userPassword, contentType); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("hostName", hostName) + .add("portNumber", portNumber) + .add("topicName", topicName) + .add("protocol", protocol) + .add("userName", userName) + .add("contentType", contentType) + .toString(); + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRConfig.java new file mode 100644 index 0000000..fd55c4c --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRConfig.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.config; + +/** + *

+ * Marker Interface for all DMaaP MR Configs. + * Holds Default configuration parameters for all Configs + *

+ * @author Rajiv Singla. Creation Date: 10/12/2016. + */ +public interface DMaaPMRConfig { + + Integer DEFAULT_PORT_NUMBER = 80; // default port number + String DEFAULT_USER_NAME = null; // default to no username + String DEFAULT_USER_PASSWORD = null; // defaults to no userPassword + String DEFAULT_PROTOCOL = "https"; // defaults to using https protocol + String DEFAULT_CONTENT_TYPE = "application/json"; // defaults to json content type + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java new file mode 100644 index 0000000..5a0e601 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfig.java @@ -0,0 +1,250 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.config; + +import com.google.common.base.Objects; + +import javax.annotation.Nonnull; + +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE; + +/** + *

+ * Immutable DMaaP MR Configuration for DMaaP MR Publisher. + *

+ * Use {@link DMaaPMRPublisherConfig.Builder} to construct Subscriber Configuration + *

+ *

+ * @author Rajiv Singla. Creation Date: 10/12/2016. + */ +public class DMaaPMRPublisherConfig extends DMaaPMRBaseConfig { + + /** + * Publisher batching queue size + */ + private int maxBatchSize; + + /** + * Publisher Recovery Queue Size + */ + private int maxRecoveryQueueSize; + + + private DMaaPMRPublisherConfig(@Nonnull String hostName, + @Nonnull Integer portNumber, + @Nonnull String topicName, + @Nonnull String protocol, + @Nonnull String userName, + @Nonnull String userPassword, + @Nonnull String contentType, + int maxBatchSize, + int maxRecoveryQueueSize) { + this.hostName = hostName; + this.portNumber = portNumber; + this.topicName = topicName; + this.protocol = protocol; + this.userName = userName; + this.userPassword = userPassword; + this.contentType = contentType; + this.maxBatchSize = maxBatchSize; + this.maxRecoveryQueueSize = maxRecoveryQueueSize; + } + + + /** + * Builder to initialize immutable {@link DMaaPMRPublisherConfig} object + */ + public static class Builder { + + private String hostName; + private Integer portNumber; + private String topicName; + private String userName; + private String userPassword; + private String protocol; + private String contentType; + private int maxBatchSize; + private int maxRecoveryQueueSize; + + public Builder(@Nonnull String hostName, @Nonnull String topicName) { + // required values + this.hostName = hostName; + this.topicName = topicName; + // Default values + this.portNumber = DEFAULT_PORT_NUMBER; + this.userName = DEFAULT_USER_NAME; + this.userPassword = DEFAULT_USER_PASSWORD; + this.protocol = DEFAULT_PROTOCOL; + this.contentType = DEFAULT_CONTENT_TYPE; + this.maxBatchSize = DEFAULT_PUBLISHER_MAX_BATCH_SIZE; + this.maxRecoveryQueueSize = DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE; + } + + /** + * Setup for custom host port number - Defaults to 80. + * + * @param portNumber custom port number + * @return Builder object itself for chaining + */ + public Builder setPortNumber(@Nonnull Integer portNumber) { + this.portNumber = portNumber; + return this; + } + + + /** + * Setup user name for authentication. If no username is provided authentication will be disabled + * + * @param userName user name for DMaaP Topic Authentication + * @return Builder object itself for chaining + */ + public Builder setUserName(@Nonnull String userName) { + this.userName = userName; + return this; + } + + + /** + * Setup user password for authentication. If no password is provided authentication will be disabled + * + * @param userPassword user password for DMaaP Topic Authentication + * @return Builder object itself for chaining + */ + public Builder setUserPassword(@Nonnull String userPassword) { + this.userPassword = userPassword; + return this; + } + + + /** + * Setup custom Publisher protocol - Defaults to https. + * Note: Only http and https are currently supported. + * + * @param protocol protocol e.g. https + * @return Builder object itself for chaining + */ + public Builder setProtocol(@Nonnull String protocol) { + this.protocol = normalizeValidateProtocol(protocol); + return this; + } + + + /** + * Setup custom Publisher content-type - Defaults to application/json + * + * @param contentType content type e.g. application/json + * @return Builder object itself for chaining + */ + public Builder setContentType(@Nonnull String contentType) { + final String normalizedContentType = normalizeValidateContentType(contentType); + this.contentType = normalizedContentType; + return this; + } + + + /** + * Setup custom Publisher Max Batch Size - Defaults to 100 + * + * @param maxBatchSize max Batch Size + * @return Builder object itself for chaining + */ + public Builder setMaxBatchSize(int maxBatchSize) { + this.maxBatchSize = maxBatchSize; + return this; + } + + + /** + * Setup custom Maximum Recovery Queue Size. Recovery Queue is used to hold messages temporarily in case + * DMaaP MR Publisher topic is not responding for any reason. Defaults to 100,000 + * + * @param maxRecoveryQueueSize max recovery queue size + * @return Builder object itself for chaining + */ + public Builder setMaxRecoveryQueueSize(int maxRecoveryQueueSize) { + this.maxRecoveryQueueSize = maxRecoveryQueueSize; + return this; + } + + /** + * Creates immutable instance of {@link DMaaPMRPublisherConfig} + * + * @return Builds and returns thread safe, immutable {@link DMaaPMRPublisherConfig} object + */ + public DMaaPMRPublisherConfig build() { + return new DMaaPMRPublisherConfig(hostName, portNumber, topicName, protocol, userName, userPassword, + contentType, maxBatchSize, maxRecoveryQueueSize); + } + + } + + + /** + * Returns max Publisher Batch Queue Size + * + * @return max Publisher Batch Queue size + */ + public int getMaxBatchSize() { + return maxBatchSize; + } + + /** + * Returns max Publisher Recovery Queue Size + * + * @return max Recovery Queue size + */ + public int getMaxRecoveryQueueSize() { + return maxRecoveryQueueSize; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + DMaaPMRPublisherConfig that = (DMaaPMRPublisherConfig) o; + return maxBatchSize == that.maxBatchSize && + maxRecoveryQueueSize == that.maxRecoveryQueueSize; + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), maxBatchSize, maxRecoveryQueueSize); + } + + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("baseConfig", super.toString()) + .add("maxBatchSize", maxBatchSize) + .add("maxRecoveryQueueSize", maxRecoveryQueueSize) + .toString(); + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java new file mode 100644 index 0000000..5e30738 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfig.java @@ -0,0 +1,298 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.config; + +import com.google.common.base.Objects; + +import java.util.UUID; + +import javax.annotation.Nonnull; + +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_GROUP_PREFIX; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_MESSAGE_LIMIT; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_TIMEOUT_MS; + +/** + *

+ * Immutable DMaaP MR Configuration for Subscriber. + *

+ * Use {@link DMaaPMRSubscriberConfig.Builder} to construct Subscriber Configuration + *

+ * + * @author Rajiv Singla. Creation Date: 10/12/2016. + */ +public final class DMaaPMRSubscriberConfig extends DMaaPMRBaseConfig { + + private final String consumerId; + private final String consumerGroup; + private final Integer timeoutMS; + private final Integer messageLimit; + + private DMaaPMRSubscriberConfig(@Nonnull String hostName, + @Nonnull Integer portNumber, + @Nonnull String topicName, + @Nonnull String protocol, + @Nonnull String userName, + @Nonnull String userPassword, + @Nonnull String contentType, + @Nonnull String consumerId, + @Nonnull String consumerGroup, + @Nonnull Integer timeoutMS, + @Nonnull Integer messageLimit) { + this.hostName = hostName; + this.portNumber = portNumber; + this.topicName = topicName; + this.protocol = protocol; + this.userName = userName; + this.userPassword = userPassword; + this.contentType = contentType; + this.consumerId = consumerId; + this.consumerGroup = consumerGroup; + this.timeoutMS = timeoutMS; + this.messageLimit = messageLimit; + } + + /** + * Builder to initialize immutable {@link DMaaPMRSubscriberConfig} object + */ + public static class Builder { + + private String hostName; + private Integer portNumber; + private String topicName; + private String userName; + private String userPassword; + private String protocol; + private String contentType; + private String consumerId; + private String consumerGroup; + private Integer timeoutMS; + private Integer messageLimit; + + public Builder(@Nonnull String hostName, + @Nonnull String topicName) { + // Required Values + this.hostName = hostName; + this.topicName = topicName; + + // Default values + this.portNumber = DEFAULT_PORT_NUMBER; + this.userName = DEFAULT_USER_NAME; + this.userPassword = DEFAULT_USER_PASSWORD; + this.protocol = DEFAULT_PROTOCOL; + this.contentType = DEFAULT_CONTENT_TYPE; + this.consumerId = UUID.randomUUID().toString(); // consumer is assigned a random id by default + this.consumerGroup = DEFAULT_SUBSCRIBER_GROUP_PREFIX + consumerId; // random group is assigned + this.timeoutMS = DEFAULT_SUBSCRIBER_TIMEOUT_MS; // defaults to 10ms timeout + this.messageLimit = DEFAULT_SUBSCRIBER_MESSAGE_LIMIT; // defaults to 1000 message limit + } + + + /** + * Setup for custom host port number - Defaults to 80. + * + * @param portNumber custom port number + * @return Builder object itself for chaining + */ + public Builder setPortNumber(@Nonnull Integer portNumber) { + this.portNumber = portNumber; + return this; + } + + + /** + * Setup user name for authentication. If no username is provided authentication will be disabled + * + * @param userName user name for DMaaP Topic Authentication + * @return Builder object itself for chaining + */ + public Builder setUserName(@Nonnull String userName) { + this.userName = userName; + return this; + } + + + /** + * Setup user password for authentication. If no password is provided authentication will be disabled + * + * @param userPassword user password for DMaaP Topic Authentication + * @return Builder object itself for chaining + */ + public Builder setUserPassword(@Nonnull String userPassword) { + this.userPassword = userPassword; + return this; + } + + + /** + * Setup custom Subscriber protocol - Defaults to https. + * Note: Only http and https are currently supported. + * + * @param protocol protocol e.g. https or http + * @return Builder object itself for chaining + */ + public Builder setProtocol(@Nonnull String protocol) { + + this.protocol = normalizeValidateProtocol(protocol); + return this; + } + + /** + * Setup custom Subscriber content-type - Defaults to application/json + * + * @param contentType content type e.g. application/json + * @return Builder object itself for chaining + */ + public Builder setContentType(@Nonnull String contentType) { + final String normalizedContentType = normalizeValidateContentType(contentType); + this.contentType = normalizedContentType; + return this; + } + + + /** + * Setup custom Consumer Id - Defaults to random Id + * + * @param consumerId - custom consumer ID + * @return Builder object itself for chaining + */ + public Builder setConsumerId(@Nonnull String consumerId) { + this.consumerId = consumerId; + return this; + } + + /** + * Setup custom Consumer Group - Default to OpenDCAE-DMaaPSub-ConsumerID + * + * @param consumerGroup - custom Consumer Group + * @return Builder object itself for chaining + */ + public Builder setConsumerGroup(@Nonnull String consumerGroup) { + this.consumerGroup = consumerGroup; + return this; + } + + /** + * Setup Custom Subscriber timeout in ms - Default to no timeout limit + * + * @param timeoutMS timeout in milliseconds + * @return Builder object itself for chaining + */ + public Builder setTimeoutMS(@Nonnull Integer timeoutMS) { + this.timeoutMS = timeoutMS; + return this; + } + + /** + * Setup custom Subscriber Message Limit - Default to no limit + * + * @param messageLimit message Limit + * @return Builder object itself for chaining + */ + public Builder setMessageLimit(@Nonnull Integer messageLimit) { + this.messageLimit = messageLimit; + return this; + } + + /** + * Builds Immutable instance of {@link DMaaPMRSubscriberConfig} + * + * @return immutable DMaaP Subscriber Config Object + */ + public DMaaPMRSubscriberConfig build() { + return new DMaaPMRSubscriberConfig(hostName, portNumber, topicName, protocol, userName, userPassword, + contentType, consumerId, consumerGroup, timeoutMS, messageLimit); + } + + } + + + /** + * DMaaP MR Subscriber Consumer Id + * + * @return consumer Id + */ + public String getConsumerId() { + return consumerId; + } + + /** + * DMaaP MR Subscriber Consumer Group + * + * @return consumer group + */ + public String getConsumerGroup() { + return consumerGroup; + } + + /** + * DMaaP MR Subscriber Timeout in ms + * + * @return subscriber timeout ms + */ + public Integer getTimeoutMS() { + return timeoutMS; + } + + /** + * DMaaP MR Subscriber message limit + * + * @return subscriber message limit + */ + public Integer getMessageLimit() { + return messageLimit; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + DMaaPMRSubscriberConfig that = (DMaaPMRSubscriberConfig) o; + return Objects.equal(consumerId, that.consumerId) && + Objects.equal(consumerGroup, that.consumerGroup) && + Objects.equal(timeoutMS, that.timeoutMS) && + Objects.equal(messageLimit, that.messageLimit); + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), consumerId, consumerGroup, timeoutMS, messageLimit); + } + + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("baseConfig", super.toString()) + .add("consumerId", consumerId) + .add("consumerGroup", consumerGroup) + .add("timeoutMS", timeoutMS) + .add("messageLimit", messageLimit) + .toString(); + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java new file mode 100644 index 0000000..d7c6f5c --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponse.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.response; + +/** + *

+ * Contract for all DMaaPMR Publisher Response + *

+ * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public interface DMaaPMRPublisherResponse extends DMaaPMRResponse { + + + /** + * Gets number of pending messages + * + * @return pending messages in the batch queue + */ + int getPendingMessagesCount(); +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java new file mode 100644 index 0000000..0ee241d --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRPublisherResponseImpl.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.response; + +import com.google.common.base.Objects; + +import javax.annotation.Nonnull; + +/** + *

+ * An simple implementation of {@link DMaaPMRPublisherResponse} + *

+ * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public class DMaaPMRPublisherResponseImpl implements DMaaPMRPublisherResponse { + + private final Integer responseCode; + private final String responseMessage; + private final int pendingMessagesCount; + + public DMaaPMRPublisherResponseImpl(@Nonnull Integer responseCode, + @Nonnull String responseMessage, + int pendingMessagesCount) { + this.responseCode = responseCode; + this.responseMessage = responseMessage; + this.pendingMessagesCount = pendingMessagesCount; + } + + @Override + public Integer getResponseCode() { + return responseCode; + } + + @Override + public String getResponseMessage() { + return responseMessage; + } + + @Override + public int getPendingMessagesCount() { + return pendingMessagesCount; + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("responseCode", responseCode) + .add("responseMessage", responseMessage) + .add("pendingMessagesCount", pendingMessagesCount) + .toString(); + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRResponse.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRResponse.java new file mode 100644 index 0000000..a8ded96 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRResponse.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.response; + +/** + *

+ * Contract for DMaaP MR Responses + *

+ * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public interface DMaaPMRResponse { + + /** + * Gets HTTP Response Code + * + * @return HTTP Response code as String + */ + Integer getResponseCode(); + + /** + * Gets Response Message + * + * @return Response Message + */ + String getResponseMessage(); + + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java new file mode 100644 index 0000000..8b7c847 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponse.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.response; + +import java.util.List; + +/** + *

+ * Contract for all DMaaP MR Subscriber Responses + *

+ * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public interface DMaaPMRSubscriberResponse extends DMaaPMRResponse { + + /** + * Returns message fetched from DMaaP MR Topic + * + * @return collection of actual message retrieved from DMaaP MR Topic + */ + List getFetchedMessages(); + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java new file mode 100644 index 0000000..2ae0c5c --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/domain/response/DMaaPMRSubscriberResponseImpl.java @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.response; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static java.util.Collections.unmodifiableList; + +/** + *

+ * A simple implementation for {@link DMaaPMRSubscriberResponse} + *

+ * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public class DMaaPMRSubscriberResponseImpl implements DMaaPMRSubscriberResponse { + + private final Integer responseCode; + private final String responseMessage; + private final List fetchedMessages; + + public DMaaPMRSubscriberResponseImpl(@Nonnull Integer responseCode, + @Nonnull String responseMessage, + @Nullable List fetchedMessages) { + this.responseCode = responseCode; + this.responseMessage = responseMessage; + this.fetchedMessages = fetchedMessages != null ? fetchedMessages : ImmutableList.of(); + } + + public DMaaPMRSubscriberResponseImpl(Integer responseCode, String responseMessage) { + this(responseCode, responseMessage, null); + } + + @Override + public Integer getResponseCode() { + return responseCode; + } + + @Override + public String getResponseMessage() { + return responseMessage; + } + + @Override + public List getFetchedMessages() { + return unmodifiableList(fetchedMessages); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("responseCode", responseCode) + .add("responseMessage", responseMessage) + .add("fetchedMessages(size)", fetchedMessages.size()) + .toString(); + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPModule.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPModule.java new file mode 100644 index 0000000..c46995f --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPModule.java @@ -0,0 +1,62 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.module; + +import com.google.inject.AbstractModule; +import com.google.inject.assistedinject.FactoryModuleBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherImpl; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueImpl; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriberFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriberImpl; + +/** + * Guice Module to wire concrete implementations with interfaces + *

+ * @author Rajiv Singla. Creation Date: 10/20/2016. + */ +public class AnalyticsDMaaPModule extends AbstractModule { + + + @Override + protected void configure() { + + // Bind Http Client + bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault()); + + // Bind Publishing queue + install(new FactoryModuleBuilder().implement(DMaaPMRPublisherQueue.class, DMaaPMRPublisherQueueImpl.class) + .build(DMaaPMRPublisherQueueFactory.class)); + + install(new FactoryModuleBuilder().implement(DMaaPMRPublisher.class, DMaaPMRPublisherImpl.class) + .build(DMaaPMRPublisherFactory.class)); + + install(new FactoryModuleBuilder().implement(DMaaPMRSubscriber.class, DMaaPMRSubscriberImpl.class) + .build(DMaaPMRSubscriberFactory.class)); + + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java new file mode 100644 index 0000000..7e16b8d --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponent.java @@ -0,0 +1,356 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Optional; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.util.EntityUtils; +import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.common.utils.HTTPUtils; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponseImpl; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponseImpl; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.util.LinkedList; +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static java.lang.String.format; + +/** + * Base class for DMaaP MR Publishers and Subscriber Implementations containing various utility methods + * + * @author Rajiv Singla. Creation Date: 11/1/2016. + */ +public abstract class BaseDMaaPMRComponent implements DMaaPMRComponent { + + private static final Logger LOG = LoggerFactory.getLogger(BaseDMaaPMRComponent.class); + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + /** + * Creates Base64 encoded Auth Header for given userName and Password + * If either user name of password are null return absent + * + * @param userName username + * @param userPassword user password + * @return base64 encoded auth header if username or password are both non null + */ + protected static Optional getAuthHeader(final @Nullable String userName, + final @Nullable String userPassword) { + if (userName == null || userPassword == null) { + return Optional.absent(); + } else { + final String auth = userName + ":" + userPassword; + final Charset isoCharset = Charset.forName("ISO-8859-1"); + byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(isoCharset)); + return Optional.of("Basic " + new String(encodedAuth, isoCharset)); + } + } + + + /** + * Creates Publisher URI for given {@link DMaaPMRPublisherConfig} + * + * @param publisherConfig publisher settings + * + * @return DMaaP MR Publisher Topic URI that can be used to post messages to MR Topic + */ + protected static URI createPublisherURI(final DMaaPMRPublisherConfig publisherConfig) { + final String hostName = publisherConfig.getHostName(); + final Integer portNumber = publisherConfig.getPortNumber(); + final String getProtocol = publisherConfig.getProtocol(); + final String topicName = publisherConfig.getTopicName(); + URI publisherURI = null; + try { + publisherURI = new URIBuilder().setScheme(getProtocol).setHost(hostName).setPort(portNumber) + .setPath(AnalyticsConstants.DMAAP_URI_PATH_PREFIX + topicName).build(); + } catch (URISyntaxException e) { + final String errorMessage = format("Error while creating publisher URI: %s", e); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + LOG.info("Created DMaaP MR Publisher URI: {}", publisherURI); + return publisherURI; + } + + + /** + * Creates Subscriber URI for given {@link DMaaPMRSubscriberConfig} + * + * @param subscriberConfig subscriber settings + * + * @return DMaaP MR Subscriber Topic URI that can be used to fetch messages from MR topic + */ + protected static URI createSubscriberURI(final DMaaPMRSubscriberConfig subscriberConfig) { + final String hostName = subscriberConfig.getHostName(); + final Integer portNumber = subscriberConfig.getPortNumber(); + final String getProtocol = subscriberConfig.getProtocol(); + final String topicName = subscriberConfig.getTopicName(); + final String consumerId = subscriberConfig.getConsumerId(); + final String consumerGroup = subscriberConfig.getConsumerGroup(); + final Integer timeoutMS = subscriberConfig.getTimeoutMS(); + final Integer messageLimit = subscriberConfig.getMessageLimit(); + URI subscriberURI = null; + try { + URIBuilder uriBuilder = new URIBuilder().setScheme(getProtocol).setHost(hostName).setPort(portNumber) + .setPath(AnalyticsConstants.DMAAP_URI_PATH_PREFIX + + topicName + "/" + + consumerGroup + "/" + + consumerId); + // add query params if present + if (timeoutMS > 0) { + uriBuilder.addParameter(AnalyticsConstants.SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME, timeoutMS.toString()); + } + if (messageLimit > 0) { + uriBuilder.addParameter(AnalyticsConstants.SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME, + messageLimit.toString()); + } + subscriberURI = uriBuilder.build(); + + } catch (URISyntaxException e) { + final String errorMessage = format("Error while creating subscriber URI: %s", e); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + + LOG.info("Created DMaaP MR Subscriber URI: {}", subscriberURI); + return subscriberURI; + } + + + /** + * Creates 202 (Accepted) Response code message + * + * @param batchQueueSize batch Queue size + * + * @return response with 202 message code + */ + protected static DMaaPMRPublisherResponse createPublisherAcceptedResponse(int batchQueueSize) { + return createPublisherResponse(HTTPUtils.HTTP_ACCEPTED_RESPONSE_CODE, + "Accepted - Messages queued for batch publishing to MR Topic", batchQueueSize); + } + + + /** + * Creates 204 (No Content) Response code message + * + * @return response with 204 message code + */ + protected static DMaaPMRPublisherResponse createPublisherNoContentResponse() { + return createPublisherResponse(HTTPUtils.HTTP_NO_CONTENT_RESPONSE_CODE, + "No Content - No Messages in batch queue for flushing to MR Topic", 0); + } + + + /** + * Creates Publisher Response for given response code, response Message and pending Message Count + * + * @param responseCode HTTP Status Code + * @param responseMessage response message + * @param pendingMessages pending messages in batch queue + * + * @return DMaaP MR Publisher Response + */ + protected static DMaaPMRPublisherResponse createPublisherResponse(int responseCode, String + responseMessage, int pendingMessages) { + return new DMaaPMRPublisherResponseImpl(responseCode, responseMessage, pendingMessages); + } + + + /** + * Returns weekly consistent pending messages in batch queue + * + * @param publisherQueue batch queue + * @param publisherConfig publisher settings + * + * @return pending messages to be published + */ + protected static int getPendingMessages(final @Nonnull DMaaPMRPublisherQueue publisherQueue, + final @Nonnull DMaaPMRPublisherConfig publisherConfig) { + return publisherConfig.getMaxBatchSize() - publisherQueue.getBatchQueueRemainingSize(); + } + + + /** + * Creates Subscriber Response for give response Code, response Message and fetch messages + * + * @param responseCode response Code + * @param responseMessage response Message + * @param fetchedMessages fetched messages + * + * @return DMaaP MR Subscriber Response + */ + protected static DMaaPMRSubscriberResponse createSubscriberResponse(int responseCode, String + responseMessage, List fetchedMessages) { + if (fetchedMessages == null) { + return new DMaaPMRSubscriberResponseImpl(responseCode, responseMessage); + } else { + return new DMaaPMRSubscriberResponseImpl(responseCode, responseMessage, fetchedMessages); + } + } + + + /** + * Custom response handler which extract status code and response body + * + * @return Pair containing Response code and response body + */ + protected static ResponseHandler> responseHandler() { + return new ResponseHandler>() { + @Override + public Pair handleResponse(HttpResponse response) throws IOException { + // Get Response status code + final int status = response.getStatusLine().getStatusCode(); + final HttpEntity responseEntity = response.getEntity(); + // If response entity is not null - extract response body as string + String responseEntityString = ""; + if (responseEntity != null) { + responseEntityString = EntityUtils.toString(responseEntity); + } + return new ImmutablePair<>(status, responseEntityString); + } + }; + } + + + /** + * Adds message to Publisher recovery queue. If recovery queue is full throws an error as messages will + * be lost + * + * @param publisherQueue publisher queue + * @param messages recoverable messages to be published to recovery queue + */ + protected static void addMessagesToRecoveryQueue(DMaaPMRPublisherQueue publisherQueue, + List messages) { + try { + publisherQueue.addRecoverableMessages(messages); + + LOG.debug("Messages Added to Recovery Queue. Messages Size: {}, Recovery Queue Remaining Size: {}", + messages.size(), publisherQueue.getBatchQueueRemainingSize()); + + } catch (IllegalStateException e) { + final String errorMessage = format("Unable to put messages in recovery queue. Messages will be lost. " + + "Recovery Queue might be full. Message Size: %d, Recovery Queue Remaining Capacity: %d", + messages.size(), publisherQueue.getRecoveryQueueRemainingSize()); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + } + + + /** + * Converts List of messages to Json String Array which can be published to DMaaP MR topic. + * + * @param messages messages that need to parsed to Json Array representation + * @return json string representation of message + */ + protected static String convertToJsonString(final @Nullable List messages) { + // If messages are null or empty just return empty array + if (messages == null || messages.size() == 0) { + return "[]"; + } + + + List jsonMessageObjectsList = new LinkedList<>(); + + try { + for (String message : messages) { + final JsonNode jsonNode = objectMapper.readTree(message); + jsonMessageObjectsList.add(jsonNode); + } + return objectMapper.writeValueAsString(jsonMessageObjectsList); + } catch (JsonProcessingException e) { + final String errorMessage = + format("Unable to convert publisher messages to Json. Messages: %s, Json Error: %s", + messages, e); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + + } catch (IOException e) { + final String errorMessage = + format("IO Exception while converting publisher messages to Json. Messages: %s, Json Error: %s", + messages, e); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + } + + + /** + * Converts subscriber messages json string to List of messages. If message Json String is empty + * or null + * + * @param messagesJsonString json messages String + * + * @return List containing DMaaP MR Messages + */ + protected static List convertJsonToStringMessages(final @Nullable String messagesJsonString) { + + final LinkedList messages = new LinkedList<>(); + + // If message string is not null or not empty parse json message array to List of string messages + if (!(messagesJsonString == null) && !messagesJsonString.trim().isEmpty() + && !messagesJsonString.trim().equals("[]")) { + + try { + final List messageList = objectMapper.readValue(messagesJsonString, List.class); + for (Object message : messageList) { + final String jsonMessageString = objectMapper.writeValueAsString(message); + if (jsonMessageString.startsWith("\"") && jsonMessageString.endsWith("\"")) { + final String jsonSubString = jsonMessageString.substring(1, jsonMessageString.length() - 1); + messages.add(StringEscapeUtils.unescapeJson(jsonSubString)); + } else { + messages.add(StringEscapeUtils.unescapeJson(jsonMessageString)); + } + } + + } catch (IOException e) { + final String errorMessage = + format("Unable to convert subscriber Json String to Messages. Subscriber Response String: %s," + + " Json Error: %s", messagesJsonString, e); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + + } + return messages; + } + + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/DMaaPMRComponent.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/DMaaPMRComponent.java new file mode 100644 index 0000000..9d891f1 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/DMaaPMRComponent.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service; + +/** + * Marker interface for all DMaaP MR Components e.g. MR Publishers, MR Subscribers + * + * @author Rajiv Singla. Creation Date: 11/1/2016. + */ +public interface DMaaPMRComponent { +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisher.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisher.java new file mode 100644 index 0000000..dcd46d9 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisher.java @@ -0,0 +1,96 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; + +import java.util.Date; +import java.util.List; + +/** + *

+ * DMaaP MR Publisher can be used to publish messages to DMaaP MR Topics. + *

+ * + * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public interface DMaaPMRPublisher extends AutoCloseable { + + + /** + *

+ * Adds collection of messages to DMaaP MR Topic Publishing Queue. + *

+ * Note: Invoking this method may or may not cause publishing immediately + * as publishing in done is batch mode by default. Parameter maxBatchSize + * in {@link DMaaPMRPublisherConfig} is used to determine max batch queue size. + * If the maxBatchSize is reached all message will be published automatically + * during subsequent call. + *

+ * + * @param messages messages to publish to DMaaP MR Publisher + * @return response which may contain Http Response code 202 (Accepted) as publishing + * will proceed when max batch size is reached + * + * @throws DCAEAnalyticsRuntimeException DCAEAnalyticsRuntimeException + */ + DMaaPMRPublisherResponse publish(List messages) throws DCAEAnalyticsRuntimeException; + + + /** + *

+ * Forces publishing of messages to DMaaP MR Topic and returns {@link DMaaPMRPublisherResponse} + * which can be inspected for HTTP status code of publishing call to DMaaP MR Topic. + *

+ * + * @param messages messages to publish to DMaaP MR Publisher + * @return DMaaP Message Router Publisher Response + * + * @throws DCAEAnalyticsRuntimeException DCAEAnalyticsRuntimeException + */ + DMaaPMRPublisherResponse forcePublish(List messages) throws DCAEAnalyticsRuntimeException; + + + /** + *

+ * Forces publishing of messages in Publisher queue to DMaaP MR Topic and returns + * {@link DMaaPMRPublisherResponse}.If there are no messages were in the queue to + * be flushed response code 304 (Not Modified) will be returned + *

+ * + * @return DMaaP Message Router Publisher Response + */ + DMaaPMRPublisherResponse flush(); + + + /** + *

+ * Returns the creation time when Publisher instance was created. + *

+ * + * @return creation time of Subscriber instance + */ + Date getPublisherCreationTime(); + + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java new file mode 100644 index 0000000..1d84011 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherFactory.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; + +/** + *

+ * Factory to initialize instance of {@link DMaaPMRPublisher} for Guice DI injection purposes. + *

+ * + * NOTE: Client should not use this Factory to initialize {@link DMaaPMRPublisher} unless they + * are wiring dependencies using Guice. Client must use {@link DMaaPMRFactory} to initialize + * guice injected Publisher instances + * + *

+ * @author Rajiv Singla. Creation Date: 10/20/2016. + */ +public interface DMaaPMRPublisherFactory { + + DMaaPMRPublisher create(DMaaPMRPublisherConfig publisherConfig); + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java new file mode 100644 index 0000000..cb62ee1 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImpl.java @@ -0,0 +1,211 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.http.HttpHeaders; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.service.BaseDMaaPMRComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.util.Date; +import java.util.List; + +import static org.openecomp.dcae.apod.analytics.common.utils.HTTPUtils.isSuccessfulResponseCode; +import static java.lang.String.format; + +/** + * Concrete Implementation of {@link DMaaPMRPublisher} which uses {@link HttpClient} + * + * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public class DMaaPMRPublisherImpl extends BaseDMaaPMRComponent implements DMaaPMRPublisher { + + private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRPublisherImpl.class); + + private final DMaaPMRPublisherConfig publisherConfig; + private final CloseableHttpClient closeableHttpClient; + private final DMaaPMRPublisherQueue publisherQueue; + private final Date publisherCreationTime; + private URI publisherUri; + + @Inject + public DMaaPMRPublisherImpl(@Assisted DMaaPMRPublisherConfig publisherConfig, + DMaaPMRPublisherQueueFactory dMaaPMRPublisherQueueFactory, + CloseableHttpClient closeableHttpClient) { + + this.publisherConfig = publisherConfig; + this.publisherQueue = dMaaPMRPublisherQueueFactory.create( + publisherConfig.getMaxBatchSize(), publisherConfig.getMaxRecoveryQueueSize()); + this.closeableHttpClient = closeableHttpClient; + this.publisherUri = createPublisherURI(publisherConfig); + this.publisherCreationTime = new Date(); + } + + + @Override + public DMaaPMRPublisherResponse publish(List messages) throws DCAEAnalyticsRuntimeException { + + final int batchQueueRemainingSize = publisherQueue.getBatchQueueRemainingSize(); + + // if messages size is less than batch queue size - just queue them for batch publishing + if (batchQueueRemainingSize > messages.size()) { + LOG.debug("Adding messages to batch Queue. No flushing required. Messages Size:{}. Batch Queue Size:{}", + messages.size(), batchQueueRemainingSize); + final int batchQueueSize = publisherQueue.addBatchMessages(messages); + return createPublisherAcceptedResponse(batchQueueSize); + + } else { + + // grab all already queued messages, append current messages and force publish them to DMaaP MR topic + final List queueMessages = publisherQueue.getMessageForPublishing(); + LOG.debug("Batch Queue capacity exceeds messages size. Flushing of all pending messages to DMaaP MR " + + "Publisher Topic."); + final DMaaPMRPublisherResponse forcePublishResponse = + forcePublish(Lists.newLinkedList(Iterables.concat(queueMessages, messages))); + return forcePublishResponse; + } + + } + + @Override + public DMaaPMRPublisherResponse forcePublish(List messages) throws DCAEAnalyticsRuntimeException { + + LOG.debug("Force publishing messages to DMaaP MR Topic. Messages Size: {}", messages.size()); + + final String contentType = publisherConfig.getContentType(); + final String userName = publisherConfig.getUserName(); + final String userPassword = publisherConfig.getUserPassword(); + final HttpPost postRequest = new HttpPost(publisherUri); + + // add Authorization Header if username and password are present + final Optional authHeader = getAuthHeader(userName, userPassword); + if (authHeader.isPresent()) { + postRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader.get()); + } else { + LOG.debug("DMaaP MR Publisher Authentication is disabled as username or password is not present."); + } + + // Create post string entity + final String messagesJson = convertToJsonString(messages); + final StringEntity requestEntity = + new StringEntity(messagesJson, ContentType.create(contentType, "UTF-8")); + postRequest.setEntity(requestEntity); + + try { + final Pair responsePair = closeableHttpClient.execute(postRequest, responseHandler()); + final Integer responseCode = responsePair.getLeft(); + final String responseBody = responsePair.getRight(); + // if messages were published successfully, return successful response + if (isSuccessfulResponseCode(responseCode)) { + LOG.debug("DMaaP MR Messages published successfully. DMaaP Response Code: {}. DMaaP Response " + + "Body: {}, Number of Messages published: {}", + responseCode, responseBody, messages.size()); + + } else { + LOG.warn("Unable to publish messages to DMaaP MR Topic. DMaaP Response Code: {}, DMaaP Response " + + "Body: {}. Messages will be queued in recovery queue", responseCode, responseBody); + addMessagesToRecoveryQueue(publisherQueue, messages); + } + + return createPublisherResponse(responseCode, responseBody, + getPendingMessages(publisherQueue, publisherConfig)); + + } catch (IOException e) { + // If IO Error then we need to also put messages in recovery queue + addMessagesToRecoveryQueue(publisherQueue, messages); + final String errorMessage = format("IO Exception while publishing messages to DMaaP Topic. " + + "Messages will be queued in recovery queue. Messages Size: %d", messages.size()); + + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + + } + + + @Override + public DMaaPMRPublisherResponse flush() { + final List queueMessages = publisherQueue.getMessageForPublishing(); + // If there are no message return 204 (No Content) response code + if (queueMessages.size() == 0) { + LOG.debug("No messages to publish to batch queue. Returning 204 status code"); + return createPublisherNoContentResponse(); + } else { + // force publish messages in queue + return forcePublish(queueMessages); + } + } + + @Override + public Date getPublisherCreationTime() { + return new Date(publisherCreationTime.getTime()); + } + + @Override + public void close() throws Exception { + + // flush current message in the queue + int retrialNumber = 0; + int flushResponseCode; + + // automatic retries if messages cannot be flushed + do { + retrialNumber++; + DMaaPMRPublisherResponse flushResponse = flush(); + flushResponseCode = flushResponse.getResponseCode(); + + if (!isSuccessfulResponseCode(flushResponseCode)) { + LOG.warn("Unable to flush batch messages to publisher due to DMaaP MR invalid Response: {}. " + + "Retrial No: {} of Max {} Retries", flushResponseCode, retrialNumber, + AnalyticsConstants.PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE); + + Thread.sleep(AnalyticsConstants.PUBLISHER_DELAY_MS_ON_RETRIES_ON_CLOSE); + } + } while (retrialNumber <= AnalyticsConstants.PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE && + !isSuccessfulResponseCode(flushResponseCode)); + + if (!isSuccessfulResponseCode(flushResponseCode)) { + LOG.error("Unable to flush batch messages to publisher. Messages loss cannot be prevented"); + } else { + LOG.info("Successfully published all batched messages to publisher."); + } + + // close http client + closeableHttpClient.close(); + + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java new file mode 100644 index 0000000..bb8fd9b --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueue.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import java.util.List; + +/** + *

+ * DMaaP MR Publisher Queue handles back pressure in case DMaaP MR Publisher topic + * is offline for some reason. It does so by having a recovery queue which keeps + * messages in order in case there is temporary interruption in DMaaP Publisher + *

+ * + * @author Rajiv Singla. Creation Date: 11/1/2016. + */ +public interface DMaaPMRPublisherQueue { + + /** + *

+ * Add batchMessages to Batch Queue + *

+ * + * @param batchMessages messages that needs to be added to batch queue + * @return current size of batch queue + * + * @throws IllegalStateException if batch queue does not have enough space + */ + int addBatchMessages(List batchMessages) throws IllegalStateException; + + + /** + *

+ * Add recoverable messages to Recoverable Queue + *

+ * + * @param recoverableMessages messages that needs to be added to recoverable queue + * @return current size of the recoverable queue + * + * @throws IllegalStateException if recoverable queue does not have enough space + */ + int addRecoverableMessages(List recoverableMessages) throws IllegalStateException; + + /** + *

+ * Get messages that need to be published to DMaaP topic. Messages in recoverable + * queue are appended if present. + *

+ * + * @return List of messages from both batch and recovery queue + */ + List getMessageForPublishing(); + + /** + *

+ * Remaining capacity of Batch Queue + *

+ * + * @return Remaining Batch Queue Size + */ + int getBatchQueueRemainingSize(); + + /** + *

+ * Remaining capacity of Recovery Queue + *

+ * + * @return Remaining Recovery Queue Size + */ + int getRecoveryQueueRemainingSize(); + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java new file mode 100644 index 0000000..75df65e --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueFactory.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import com.google.inject.assistedinject.Assisted; + +/** + *

+ * Factory to initialize instance of {@link DMaaPMRPublisherQueue} for Guice DI injection purposes. + *

+ * + * @author Rajiv Singla. Creation Date: 11/1/2016. + */ +public interface DMaaPMRPublisherQueueFactory { + + DMaaPMRPublisherQueue create(@Assisted("batchQueueSize") int batchQueueSize, + @Assisted("recoveryQueueSize") int recoveryQueueSize); + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java new file mode 100644 index 0000000..b293998 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImpl.java @@ -0,0 +1,124 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.LinkedBlockingDeque; + +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Lists.newLinkedList; +import static java.util.Collections.unmodifiableList; + +/** + *

+ * An implementation of {@link DMaaPMRPublisherQueue} which uses {@link java.util.concurrent.BlockingDeque} + * for batch and recovery queues + *

+ * + * + * @author Rajiv Singla. Creation Date: 11/1/2016. + */ +public class DMaaPMRPublisherQueueImpl implements DMaaPMRPublisherQueue { + + private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRPublisherQueueImpl.class); + + private final LinkedBlockingDeque batchQueue; + private final LinkedBlockingDeque recoveryQueue; + + @Inject + public DMaaPMRPublisherQueueImpl(@Assisted("batchQueueSize") int batchQueueSize, + @Assisted("recoveryQueueSize") int recoveryQueueSize) { + batchQueue = new LinkedBlockingDeque<>(batchQueueSize); + recoveryQueue = new LinkedBlockingDeque<>(recoveryQueueSize); + LOG.debug("Creating Instance of DMaaP Publisher Queue. BatchQueueSize: {}, RecoveryQueueSize: {}", + batchQueueSize, recoveryQueueSize); + } + + @Override + public synchronized int addBatchMessages(List batchMessages) throws IllegalStateException { + + // checks if batchMessages size does not exceed batch queue capacity + if (batchMessages.size() > batchQueue.remainingCapacity()) { + throw new IllegalStateException("Not enough capacity to add batchMessages in batch queue"); + } + + // Add batchMessages to batch queue + for (String message : batchMessages) { + batchQueue.add(message); + } + + // returns current elements size in batch queue + return batchQueue.size(); + } + + @Override + public synchronized int addRecoverableMessages(List recoverableMessages) throws IllegalStateException { + + // checks if messages size does not exceed recovery queue size + if (recoverableMessages.size() > recoveryQueue.remainingCapacity()) { + throw new IllegalStateException("Not enough capacity to add messages in recovery queue"); + } + + // add messages to recovery queue + for (String recoverableMessage : recoverableMessages) { + recoveryQueue.add(recoverableMessage); + } + + // returns current size of recovery queue + return recoveryQueue.size(); + } + + @Override + public synchronized List getMessageForPublishing() { + + final List recoveryMessageList = new LinkedList<>(); + final List batchMessagesList = new LinkedList<>(); + + // get messages from recovery queue if present + if (recoveryQueue.size() > 0) { + recoveryQueue.drainTo(recoveryMessageList); + } + + // get messages from batch queue if present + if (batchQueue.size() > 0) { + batchQueue.drainTo(batchMessagesList); + } + + // concat recovery and batch queue elements + return unmodifiableList(newLinkedList(concat(recoveryMessageList, batchMessagesList))); + } + + @Override + public synchronized int getBatchQueueRemainingSize() { + return batchQueue.remainingCapacity(); + } + + @Override + public synchronized int getRecoveryQueueRemainingSize() { + return recoveryQueue.remainingCapacity(); + } +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java new file mode 100644 index 0000000..33fe83e --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriber.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.subscriber; + +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; + +import java.util.Date; + +/** + *

+ * DMaaP MR Subscriber can be used to subscribe messages from DMaaP MR Topics. + *

+ * + * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public interface DMaaPMRSubscriber extends AutoCloseable { + + /** + * Fetches Messages from DMaaP MR Topic. {@link DMaaPMRPublisherConfig} settings parameters + * for messageLimit and message timeout are used + * + * @return DMaaP Message Router Subscriber Response + * + * @throws DCAEAnalyticsRuntimeException DCAE Analytics Exception + */ + DMaaPMRSubscriberResponse fetchMessages() throws DCAEAnalyticsRuntimeException; + + + /** + * Returns the Subscriber instance creation time + *

+ * NOTE: Due to DMaaP API Design - Subscribers can only fetch messages which + * are published to the topic after the creation of the Subscriber. + * + * @return creation time of Subscriber instance + */ + Date getSubscriberCreationTime(); + + +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java new file mode 100644 index 0000000..be114f6 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberFactory.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.subscriber; + +import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; + +/** + * Factory to initialize instance of {@link DMaaPMRSubscriber} for Guice DI injection purposes. + *

+ * + * NOTE: Client should not use this Factory to initialize {@link DMaaPMRSubscriber} unless they + * are wiring dependencies using Guice. Client must use {@link DMaaPMRFactory} to initialize + * guice injected Subscriber instances + * + *

+ * @author Rajiv Singla. Creation Date: 10/20/2016. + */ +public interface DMaaPMRSubscriberFactory { + + DMaaPMRSubscriber create(DMaaPMRSubscriberConfig subscriberConfig); +} diff --git a/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java new file mode 100644 index 0000000..2729b55 --- /dev/null +++ b/dcae-analytics-dmaap/src/main/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImpl.java @@ -0,0 +1,129 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.subscriber; + +import com.google.common.base.Optional; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.http.HttpHeaders; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.openecomp.dcae.apod.analytics.dmaap.service.BaseDMaaPMRComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import static org.openecomp.dcae.apod.analytics.common.utils.HTTPUtils.isSuccessfulResponseCode; +import static java.lang.String.format; + +/** + * Concrete Implementation of {@link DMaaPMRSubscriber} which uses {@link HttpClient} + * + * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public class DMaaPMRSubscriberImpl extends BaseDMaaPMRComponent implements DMaaPMRSubscriber { + + private static final Logger LOG = LoggerFactory.getLogger(DMaaPMRSubscriberImpl.class); + + private final DMaaPMRSubscriberConfig subscriberConfig; + private final CloseableHttpClient closeableHttpClient; + private final URI subscriberUri; + private final Date subscriberCreationTime; + + @Inject + public DMaaPMRSubscriberImpl(@Assisted DMaaPMRSubscriberConfig subscriberConfig, + CloseableHttpClient closeableHttpClient) { + this.subscriberConfig = subscriberConfig; + this.closeableHttpClient = closeableHttpClient; + this.subscriberUri = createSubscriberURI(subscriberConfig); + this.subscriberCreationTime = new Date(); + } + + @Override + public DMaaPMRSubscriberResponse fetchMessages() throws DCAEAnalyticsRuntimeException { + + final String userName = subscriberConfig.getUserName(); + final String userPassword = subscriberConfig.getUserPassword(); + + final HttpGet getRequest = new HttpGet(subscriberUri); + + // add Authorization Header if username and password are present + final Optional authHeader = getAuthHeader(userName, userPassword); + if (authHeader.isPresent()) { + getRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader.get()); + } else { + LOG.debug("DMaaP MR Subscriber Authentication is disabled as username or password is not present."); + } + + try { + + final Pair responsePair = closeableHttpClient.execute(getRequest, responseHandler()); + final Integer responseCode = responsePair.getLeft(); + final String responseBody = responsePair.getRight(); + + List fetchedMessages = new LinkedList<>(); + String responseMessage = responseBody; + + // if messages were published successfully, return successful response + if (isSuccessfulResponseCode(responseCode)) { + if (responseBody != null) { + fetchedMessages = convertJsonToStringMessages(responseBody); + responseMessage = "Messages Fetched Successfully"; + } else { + responseMessage = "DMaaP Response Body had no messages"; + } + } else { + LOG.error("Unable to fetch messages to DMaaP MR Topic. DMaaP MR unsuccessful Response Code: {}, " + + "DMaaP Response Body: {}", responseCode, responseBody); + } + + return createSubscriberResponse(responseCode, responseMessage, fetchedMessages); + + } catch (IOException e) { + + final String errorMessage = + format("IO Exception while fetching messages from DMaaP Topic. Exception %s", e); + throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e); + } + + + } + + @Override + public Date getSubscriberCreationTime() { + return new Date(subscriberCreationTime.getTime()); + } + + @Override + public void close() throws Exception { + closeableHttpClient.close(); + } +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java deleted file mode 100644 index 522b057..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap; - -import org.junit.runner.RunWith; -import org.openecomp.dcae.analytics.test.runner.GuiceJUnitRunner; - -/** - * @author Rajiv Singla. Creation Date: 10/20/2016. - */ -@RunWith(GuiceJUnitRunner.class) -public abstract class BaseAnalyticsDMaaPGuiceUnitTest extends BaseAnalyticsDMaaPUnitTest { -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java deleted file mode 100644 index 75e3ec4..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap; - -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.test.BaseDCAEAnalyticsUnitTest; - -import java.util.List; - -import static com.google.common.collect.ImmutableList.of; - -/** - * @author Rajiv Singla. Creation Date: 10/14/2016. - */ -public abstract class BaseAnalyticsDMaaPUnitTest extends BaseDCAEAnalyticsUnitTest { - - // Unit Test Settings - protected static final String HOST_NAME = "testHostName"; - protected static final Integer PORT_NUMBER = 8080; - protected static final String TOPIC_NAME = "testTopicName"; - protected static final String USERNAME = "testUserName"; - protected static final String PASSWORD = "testPassword"; - protected static final String HTTP_PROTOCOL = "https"; - protected static final String CONTENT_TYPE = "application/json"; - - protected static final int PUBLISHER_MAX_BATCH_QUEUE_SIZE = 200; - protected static final int PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 2000; - - protected static final String SUBSCRIBER_CONSUMER_ID = "123"; - protected static final String SUBSCRIBER_CONSUMER_GROUP_NAME = "testGonsumerName-" + SUBSCRIBER_CONSUMER_ID; - protected static final int SUBSCRIBER_TIMEOUT_MS = 2000; - protected static final int SUBSCRIBER_MESSAGE_LIMIT = 20; - - /** - * Creates Sample Publisher settings for unit testing purposes - * - * @return sample publisher settings for testing - */ - protected static DMaaPMRPublisherConfig getPublisherConfig() { - return new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setProtocol(HTTP_PROTOCOL) - .setUserName(USERNAME) - .setUserPassword(PASSWORD) - .setContentType(CONTENT_TYPE) - .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) - .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE).build(); - } - - /** - * Creates Sample Subscriber settings for unit testing purposes - * - * @return sample subscriber settings for testing - */ - protected static DMaaPMRSubscriberConfig getSubscriberConfig(String consumerId, String consumerGroup) { - return new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setUserName(USERNAME) - .setUserPassword(PASSWORD) - .setProtocol(HTTP_PROTOCOL) - .setContentType(CONTENT_TYPE) - .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME) - .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID) - .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) - .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build(); - } - - /** - * Creates two sample message for publishing - * - * @return sample publish message list - */ - protected static List getTwoSampleMessages() { - String message1 = "{ \"message\" : \"Test Message1\"}"; - String message2 = "{ \"message\" : \"Test Message2\"}"; - return of(message1, message2); - } - - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactoryTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactoryTest.java deleted file mode 100644 index 646b48d..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/DMaaPMRFactoryTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap; - -import org.junit.Before; -import org.junit.Test; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.analytics.dmaap.module.AnalyticsDMaaPTestModule; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; -import org.openecomp.dcae.analytics.test.annotation.GuiceModules; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -/** - * @author Manjesh Gowda. Creation Date: 11/7/2016. - */ -@GuiceModules(AnalyticsDMaaPTestModule.class) -public class DMaaPMRFactoryTest extends BaseAnalyticsDMaaPGuiceUnitTest { - - private DMaaPMRFactory dmaapMRFactory; - - @Before - public void setUp() throws Exception { - dmaapMRFactory = new DMaaPMRFactory(new AnalyticsDMaaPTestModule()); - } - - @Test - public void createPublisher() throws Exception { - DMaaPMRPublisher publisher = dmaapMRFactory.createPublisher(getPublisherConfig()); - DMaaPMRPublisherResponse response = publisher.publish(null); - assertThat(response.getResponseCode(), is(102)); - } - - @Test - public void createSubscriber() throws Exception { - DMaaPMRSubscriber dmaapMRSubscriber = dmaapMRFactory.createSubscriber(getSubscriberConfig("", "")); - DMaaPMRSubscriberResponse response = dmaapMRSubscriber.fetchMessages(); - assertThat(response.getResponseCode(), is(102)); - } - - @Test - public void create() throws Exception { - - } - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java deleted file mode 100644 index a66d3f2..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.config; - -import org.junit.Test; -import org.openecomp.dcae.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; - -import static org.junit.Assert.assertTrue; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_CONTENT_TYPE; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PORT_NUMBER; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PROTOCOL; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_USER_NAME; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_USER_PASSWORD; - -/** - * @author Rajiv Singla. Creation Date: 10/14/2016. - */ -public class DMaaPMRPublisherConfigTest extends BaseAnalyticsDMaaPUnitTest { - - - @Test - public void testPublisherConfigDefaults() throws Exception { - - final DMaaPMRPublisherConfig actualDefaultPublisherConfig = - new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME).build(); - - final DMaaPMRPublisherConfig expectedDefaultPublisherConfig = - new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(DEFAULT_PORT_NUMBER) - .setUserName(DEFAULT_USER_NAME) - .setUserPassword(DEFAULT_USER_PASSWORD) - .setContentType(DEFAULT_CONTENT_TYPE) - .setProtocol(DEFAULT_PROTOCOL) - .setMaxBatchSize(DEFAULT_PUBLISHER_MAX_BATCH_SIZE) - .setMaxRecoveryQueueSize(DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) - .build(); - - assertTrue("Default Publisher Config parameters must match", - actualDefaultPublisherConfig.equals(expectedDefaultPublisherConfig)); - - } - - - @Test - public void testPublisherCustomConfig() throws Exception { - - - final DMaaPMRPublisherConfig actualCustomPublisherConfig = getPublisherConfig(); - - final DMaaPMRPublisherConfig expectedCustomPublisherConfig = - new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setUserName(USERNAME) - .setUserPassword(PASSWORD) - .setContentType(CONTENT_TYPE) - .setProtocol(HTTP_PROTOCOL) - .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE) - .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) - .build(); - - assertTrue("Custom Publisher Config parameters must match", - actualCustomPublisherConfig.equals(expectedCustomPublisherConfig)); - } - - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java deleted file mode 100644 index 10edc0c..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.domain.config; - -import org.junit.Test; -import org.openecomp.dcae.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; - -import static org.junit.Assert.assertTrue; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_GROUP_PREFIX; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_MESSAGE_LIMIT; -import static org.openecomp.dcae.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_TIMEOUT_MS; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_CONTENT_TYPE; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PORT_NUMBER; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PROTOCOL; -import static org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_USER_NAME; - -/** - * @author Rajiv Singla. Creation Date: 10/14/2016. - */ -public class DMaaPMRSubscriberConfigTest extends BaseAnalyticsDMaaPUnitTest { - - @Test - public void testSubscriberConfigDefaults() throws Exception { - - DMaaPMRSubscriberConfig actualDefaultSubscriberConfig = - new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) - .setConsumerGroup(DEFAULT_SUBSCRIBER_GROUP_PREFIX + SUBSCRIBER_CONSUMER_ID) - .setConsumerId(SUBSCRIBER_CONSUMER_ID).build(); - - DMaaPMRSubscriberConfig expectedSubscriberConfig = - new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(DEFAULT_PORT_NUMBER) - .setUserName(DEFAULT_USER_NAME) - .setContentType(DEFAULT_CONTENT_TYPE) - .setProtocol(DEFAULT_PROTOCOL) - .setConsumerGroup(DEFAULT_SUBSCRIBER_GROUP_PREFIX + SUBSCRIBER_CONSUMER_ID) - .setConsumerId(SUBSCRIBER_CONSUMER_ID) - .setMessageLimit(DEFAULT_SUBSCRIBER_MESSAGE_LIMIT) - .setTimeoutMS(DEFAULT_SUBSCRIBER_TIMEOUT_MS) - .build(); - - assertTrue("Default Subscriber Config parameters must match", - actualDefaultSubscriberConfig.equals(expectedSubscriberConfig)); - - } - - - @Test - public void testSubscriberCustomConfig() throws Exception { - - DMaaPMRSubscriberConfig actualSubscriberCustomConfig = getSubscriberConfig(SUBSCRIBER_CONSUMER_ID, - SUBSCRIBER_CONSUMER_GROUP_NAME); - - DMaaPMRSubscriberConfig expectedSubscriberCustomConfig = - new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setUserName(USERNAME) - .setUserPassword(PASSWORD) - .setContentType(CONTENT_TYPE) - .setProtocol(HTTP_PROTOCOL) - .setConsumerGroup(SUBSCRIBER_CONSUMER_GROUP_NAME) - .setConsumerId(SUBSCRIBER_CONSUMER_ID) - .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT) - .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) - .build(); - - assertTrue("Custom Subscriber Config parameters must match", - actualSubscriberCustomConfig.equals(expectedSubscriberCustomConfig)); - - } - - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java deleted file mode 100644 index 987b57b..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.it; - -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.openecomp.dcae.analytics.test.BaseDCAEAnalyticsIT; - -import java.util.List; - -import static com.google.common.collect.ImmutableList.of; - -/** - * Base class for all DCAE DMaaP Integration Tests - *

- * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public abstract class BaseAnalyticsDMaaPIT extends BaseDCAEAnalyticsIT { - - // Integration Test Settings - protected static final String HOST_NAME = "mrlocal-mtnjftle01.homer.com"; - protected static final Integer PORT_NUMBER = 3905; - protected static final String TOPIC_NAME = "com.dcae.dmaap.mtnje2.DcaeTestVESPub"; - - protected static final String USERNAME = "m00502@tca.af.dcae.com"; - protected static final String PASSWORD = "Te5021abc"; - protected static final String HTTP_PROTOCOL = "https"; - protected static final String CONTENT_TYPE = "application/json"; - - protected static final int PUBLISHER_MAX_BATCH_QUEUE_SIZE = 20; - protected static final int PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 200; - - protected static final String SUBSCRIBER_CONSUMER_ID = "123"; - protected static final String SUBSCRIBER_CONSUMER_GROUP_NAME = "testGonsumerName-" + SUBSCRIBER_CONSUMER_ID; - protected static final int SUBSCRIBER_TIMEOUT_MS = 2000; - protected static final int SUBSCRIBER_MESSAGE_LIMIT = 20; - - /** - * Creates Sample Publisher settings for integration testing purposes - * - * @return - */ - protected static DMaaPMRPublisherConfig getPublisherConfig() { - return new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setProtocol(HTTP_PROTOCOL) - .setContentType(CONTENT_TYPE) - .setUserName(USERNAME) - .setUserPassword(PASSWORD) - .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE) - .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) - .build(); - } - - /** - * Creates Sample Subscriber settings for integration testing purposes - * - * @return - */ - protected static DMaaPMRSubscriberConfig getSubscriberConfig(String consumerId) { - return new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setProtocol(HTTP_PROTOCOL) - .setContentType(CONTENT_TYPE) - .setUserName(USERNAME) - .setUserPassword(PASSWORD) - .setConsumerGroup(SUBSCRIBER_CONSUMER_GROUP_NAME) - .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID) - .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) - .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build(); - } - - /** - * Publishes 2 sample message to DMaaP Topic for integration test purposes - * - * @param dMaaPMRPublisher - * @return - */ - protected static DMaaPMRPublisherResponse publishTwoSampleMessages(DMaaPMRPublisher dMaaPMRPublisher) { - DMaaPMRPublisherResponse dMaaPMRPublisherResponse = dMaaPMRPublisher.publish(getTwoSampleMessage()); - return dMaaPMRPublisherResponse; - } - - protected static List getTwoSampleMessage() { - String message1 = "{ \"message\" : \"Test Message1\"}"; - String message2 = "{ \"message\" : \"Test Message2\"}"; - return of(message1, message2); - } - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRPublisherImplIT.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRPublisherImplIT.java deleted file mode 100644 index a7e1f8c..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRPublisherImplIT.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.it; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.dcae.analytics.dmaap.DMaaPMRFactory; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; - -/** - * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public class DMaaPMRPublisherImplIT extends BaseAnalyticsDMaaPIT { - - private DMaaPMRPublisher dMaaPMRPublisher; - - @Before - public void before() throws Exception { - DMaaPMRFactory dMaaPMRFactory = DMaaPMRFactory.create(); - dMaaPMRPublisher = dMaaPMRFactory.createPublisher(getPublisherConfig()); - } - - @Test - public void testPublish() throws Exception { - long pendingMessageCount = publishTwoSampleMessages(dMaaPMRPublisher).getPendingMessagesCount(); - Assert.assertTrue("Published Message Count must be 2", pendingMessageCount == 2); - } - - @Test - public void testFlush() throws Exception { - publishTwoSampleMessages(dMaaPMRPublisher); - DMaaPMRPublisherResponse publisherResponse = dMaaPMRPublisher.flush(); - Integer responseCode = publisherResponse.getResponseCode(); - Assert.assertTrue("Server Response code must be 200", responseCode == 200); - } -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java deleted file mode 100644 index 4b32e96..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.it; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.dcae.analytics.dmaap.DMaaPMRFactory; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; - -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; - -import static org.junit.Assert.assertTrue; - -/** - * @author Rajiv Singla. Creation Date: 10/13/2016. - */ -public class DMaaPMRSubscriberImplIT extends BaseAnalyticsDMaaPIT { - - private DMaaPMRPublisher dMaaPMRPublisher; - private DMaaPMRSubscriber dMaaPMRSubscriber; - - @Before - public void before() throws Exception { - String randomConsumerID = UUID.randomUUID().toString(); - DMaaPMRFactory dMaaPMRFactory = DMaaPMRFactory.create(); - dMaaPMRSubscriber = dMaaPMRFactory.createSubscriber(getSubscriberConfig(randomConsumerID)); - dMaaPMRPublisher = dMaaPMRFactory.createPublisher(getPublisherConfig()); - } - - @After - public void after() throws Exception { - dMaaPMRSubscriber.close(); - dMaaPMRPublisher.close(); - } - - - @Test - public void testFetchMessages() throws Exception { - - // This call is used to just register a brand new subscriber with DMaaP - DMaaPMRSubscriberResponse subscriberRegistrationResponse = dMaaPMRSubscriber.fetchMessages(); - assertTrue("Subscriber Registration Response code must be 200 confirming subscriber was registered " + - "successfully", subscriberRegistrationResponse.getResponseCode() == 200); - assertTrue("Subscriber Registration Response must not contain any messages", subscriberRegistrationResponse - .getFetchedMessages().size() == 0); - - // Force push couple of test messages - DMaaPMRPublisherResponse publisherResponse = dMaaPMRPublisher.forcePublish(getTwoSampleMessage()); - assertTrue("Message must be posted successfully before subscriber can fetch it", publisherResponse - .getResponseCode() == 200); - - // Now fetch messages from DMaaP - DMaaPMRSubscriberResponse subscriberResponse = dMaaPMRSubscriber.fetchMessages(); - List messageList = new LinkedList<>(); - for (String message : subscriberResponse.getFetchedMessages()) { - messageList.add(message); - } - assertTrue("Subscriber message count must be 2", messageList.size() == 2); - } - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPTestModule.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPTestModule.java deleted file mode 100644 index 7ef44aa..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/module/AnalyticsDMaaPTestModule.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.module; - -import com.google.inject.AbstractModule; -import com.google.inject.assistedinject.FactoryModuleBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisher; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherFactory; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherMockImpl; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueFactory; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueImpl; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriberFactory; -import org.openecomp.dcae.analytics.dmaap.service.subscriber.DMaaPMRSubscriberMockImpl; - -/** - * DMaaP Guice Test Module - *

- * @author Rajiv Singla. Creation Date: 10/20/2016. - */ -public class AnalyticsDMaaPTestModule extends AbstractModule { - - - @Override - protected void configure() { -// Bind Http Client - bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault()); - - // Bind Publishing queue - install(new FactoryModuleBuilder().implement(DMaaPMRPublisherQueue.class, DMaaPMRPublisherQueueImpl.class) - .build(DMaaPMRPublisherQueueFactory.class)); - - install(new FactoryModuleBuilder().implement(DMaaPMRPublisher.class, DMaaPMRPublisherMockImpl.class) - .build(DMaaPMRPublisherFactory.class)); - - install(new FactoryModuleBuilder().implement(DMaaPMRSubscriber.class, DMaaPMRSubscriberMockImpl.class) - .build(DMaaPMRSubscriberFactory.class)); - } -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponentTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponentTest.java deleted file mode 100644 index 4cc3f1e..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/BaseDMaaPMRComponentTest.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Optional; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.client.ResponseHandler; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; - -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.isA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * @author Manjesh Gowda. Creation Date: 11/4/2016. - */ -public class BaseDMaaPMRComponentTest extends BaseAnalyticsDMaaPUnitTest { - - //region Get Authorization Header Tests - @Test - public void testGetAuthHeaderWithGoodValues() { - String expectedEncodedString = "Basic bTAwNTAyQHRjYS5hZi5kY2FlLmNvbTpUZTUwMjFhYmM="; - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("m00502@tca.af.dcae.com", "Te5021abc"); - assertTrue(" Authentication Header has value ", actualOutput.isPresent()); - assertEquals(" Authentication Header has value ", expectedEncodedString, actualOutput.get()); - } - - @Test - public void testGetAuthHeaderWithNullValues() { - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader(null, null); - assertFalse(" Authentication Header has value ", actualOutput.isPresent()); - } - - @Test - public void testGetAuthHeaderWithUserNullValue() { - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("m00502@tca.af.dcae.com", null); - assertFalse(" Authentication Header has value ", actualOutput.isPresent()); - } - - @Test - public void testGetAuthHeaderWithPasswordNullValue() { - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader(null, "Te5021abc"); - assertFalse(" Authentication Header has value ", actualOutput.isPresent()); - } - - /* @Test - public void testGetAuthHeaderWithEmptyValues() { - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("", ""); - assertFalse(" Authentication Header has value ", actualOutput.isPresent()); - } - - @Test - public void testGetAuthHeaderWithUserEmptyValue() { - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("m00502@tca.af.dcae.com", ""); - assertFalse(" Authentication Header has value ", actualOutput.isPresent()); - } - - @Test - public void testGetAuthHeaderWithPasswordEmptyValue() { - Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("", "Te5021abc"); - assertFalse(" Authentication Header has value ", actualOutput.isPresent()); - }*/ - //endregion - - //region Publisher URI Tests - @Test - public void testCreatePublishURIWithGoodValues() { - URI actualURI = BaseDMaaPMRComponent.createPublisherURI(getPublisherConfig()); - String test = actualURI.toString(); - assertEquals("Generated Publisher URL is correct", - "https://testHostName:8080/events/testTopicName", actualURI.toString()); - } - - @Test(expected = DCAEAnalyticsRuntimeException.class) - public void testCreatePublishURIWithURISyntaxException() { - DMaaPMRPublisherConfig badPublisherConfig = new DMaaPMRPublisherConfig - .Builder(" dav /gh. ss/ asd ", "///@$%#-htps:<>!##") - .setPortNumber(0) - .setProtocol("https").build(); - - URI actualURI = BaseDMaaPMRComponent.createPublisherURI(badPublisherConfig); - } - - //endregion - - //region Subscriber URI Tests - @Test - public void testCreateSubscribeURIWithGoodValues() { - URI actualURI = BaseDMaaPMRComponent.createSubscriberURI( - getSubscriberConfig("test-consumer-group", "test-consumer-id")); - assertEquals("Generated Subscriber URL is correct", - "https://testHostName:8080/events/testTopicName/" + - "test-consumer-id/test-consumer-group?timeout=2000&limit=20", - actualURI.toString()); - } - - @Test(expected = DCAEAnalyticsRuntimeException.class) - public void testCreateSubscribeURIWithURISyntaxException() { - DMaaPMRSubscriberConfig badSubscriberConfig = new DMaaPMRSubscriberConfig - .Builder(" dav /gh. ss/ asd ", "") - .setPortNumber(PORT_NUMBER) - .setProtocol(HTTP_PROTOCOL) - .setContentType(CONTENT_TYPE).build(); - - URI actualURI = BaseDMaaPMRComponent.createSubscriberURI(badSubscriberConfig); - } - - //endregion - - //region Convert toJSON String tests - @Test - public void testConvertToJsonStringGoodJsonStringList() { - List jsonMessage = Arrays.asList( - "{\"message\":\"I'm Object 1 Message\"}", - "{\"message\":\"I'm Object 2 Message\"}"); - - String actualJSONMsg = BaseDMaaPMRComponent.convertToJsonString(jsonMessage); - - String expectedJSONMsg = "[{\"message\":\"I'm Object 1 Message\"}," + - "{\"message\":\"I'm Object 2 Message\"}]"; - assertEquals("Convert a List of Strings to JSON is working fine", expectedJSONMsg, actualJSONMsg); - - } - - @Rule - public ExpectedException expectedJsonProcessingException = ExpectedException.none(); - - @Test - public void testConvertToJsonStringBadJsonStringList() { - expectedJsonProcessingException.expect(DCAEAnalyticsRuntimeException.class); - expectedJsonProcessingException.expectCause(isA(JsonProcessingException.class)); - - List jsonMessage = Arrays.asList( - "{\"message\":\"I'm Object 1 Message\"", - "\"message\":\"I'm Object 2 Message\""); - - BaseDMaaPMRComponent.convertToJsonString(jsonMessage); - } - - @Test - public void testConvertToJsonStringWithEmptyList() { - List jsonMessage = Arrays.asList(); - String actualJSONMsg = BaseDMaaPMRComponent.convertToJsonString(jsonMessage); - String expectedJSONMsg = "[]"; - assertEquals("Convert a List of Strings to JSON is working fine", expectedJSONMsg, actualJSONMsg); - } - - @Test - public void testConvertToJsonStringWithNullList() { - String actualJSONMsg = BaseDMaaPMRComponent.convertToJsonString(null); - String expectedJSONMsg = "[]"; - assertEquals("Convert a List of Strings to JSON is working fine", expectedJSONMsg, actualJSONMsg); - } - - //endregion - - //region Convert JSONtoString String tests - - @Test - public void testConvertJsonToStringMessagesGoodValues() { - String inputJSONMsg = "[{\"message\":\"I'm Object 1 Message\"}," + - "{\"message\":\"I'm Object 2 Message\"}]"; - List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(inputJSONMsg); - assertThat(actualList, hasSize(2)); - assertThat(actualList, containsInAnyOrder( - "{\"message\":\"I'm Object 1 Message\"}", - "{\"message\":\"I'm Object 2 Message\"}" - )); - } - - @Test - public void testConvertJsonToStringMessagesNoValues() { - String inputJSONMsg = "[]"; - List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(inputJSONMsg); - assertThat(actualList, hasSize(0)); - } - - @Test - public void testConvertJsonToStringMessagesNullValues() { - List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(null); - assertThat(actualList, hasSize(0)); - } - - @Test - public void testConvertJsonToStringMessagesEmptyValues() { - List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(" "); - assertThat(actualList, hasSize(0)); - } - - @Rule - public ExpectedException convertToJSONIOException = ExpectedException.none(); - - @Test - public void testConvertJsonToStringMessagesException() { - convertToJSONIOException.expect(DCAEAnalyticsRuntimeException.class); - convertToJSONIOException.expectCause(isA(IOException.class)); - - String inputJSONMsg = "[\"{\"message\":\"I'm Object 1 Message\"}\"," + - "\"{\"message\":\"I'm Object 2 Message\"}\"]"; - List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(inputJSONMsg); - assertThat(actualList, hasSize(2)); - assertThat(actualList, containsInAnyOrder( - "{\"message\":\"I'm Object 1 Message\"}", - "{\"message\":\"I'm Object 2 Message\"}" - )); - } - - //endregion - - //region Test add message to recovery queue - @Test - public void testAddMessagesToRecoveryQueueAllGood() { - DMaaPMRPublisherQueue dmaapMRPublisherQueue = mock(DMaaPMRPublisherQueue.class); - given(dmaapMRPublisherQueue.addRecoverableMessages(Mockito.anyList())).willReturn(0); - given(dmaapMRPublisherQueue.getBatchQueueRemainingSize()).willReturn(0); - List messages = new ArrayList(); - BaseDMaaPMRComponent.addMessagesToRecoveryQueue(dmaapMRPublisherQueue, messages); - } - - @Rule - public ExpectedException addQueueIllegalException = ExpectedException.none(); - - @Test - public void testAddMessagesToRecoveryQueueException() { - addQueueIllegalException.expect(isA(DCAEAnalyticsRuntimeException.class)); - addQueueIllegalException.expectCause(isA(IllegalStateException.class)); - - DMaaPMRPublisherQueue dmaapMRPublisherQueue = mock(DMaaPMRPublisherQueue.class); - - given(dmaapMRPublisherQueue.addRecoverableMessages(Mockito.anyList())) - .willThrow(IllegalStateException.class); - List messages = new ArrayList(); - - BaseDMaaPMRComponent.addMessagesToRecoveryQueue(dmaapMRPublisherQueue, messages); - } - - //endregion - - //region Miscellaneous tests - - @Test - public void testResponseHandler() { - HttpResponse mockHttpResponse = mock(HttpResponse.class); - StatusLine mockStatusLine = mock(StatusLine.class); - HttpEntity mockHttpEntity = mock(HttpEntity.class); - // Could not mock EntityUtils as it's final class - //EntityUtils mockEntityUtils = mock(EntityUtils.class); - - given(mockHttpResponse.getStatusLine()).willReturn(mockStatusLine); - given(mockStatusLine.getStatusCode()).willReturn(200); - given(mockHttpResponse.getEntity()).willReturn(null); - //given(mockEntityUtils.toString()).willReturn("Test value"); - - ResponseHandler> responseHandler = BaseDMaaPMRComponent.responseHandler(); - try { - Pair mappedResponse = responseHandler.handleResponse(mockHttpResponse); - assertTrue("Http response code returned properly ", mappedResponse.getLeft().equals(200)); - assertTrue("Http response body returned properly ", mappedResponse.getRight().equals("")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - //endregion - - //region createSubscriberResponse tests - @Test - public void testCreateSubscriberResponse() { - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = - BaseDMaaPMRComponent.createSubscriberResponse(200, "Test Message", getTwoSampleMessages()); - - assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); - assertEquals(dmaapMRSubscriberResponse.getResponseMessage(), "Test Message"); - assertThat(dmaapMRSubscriberResponse.getFetchedMessages().size(), is(2)); - - } - - @Test - public void testCreateSubscriberResponse_no_message() { - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = - BaseDMaaPMRComponent.createSubscriberResponse(200, "Test Message", null); - - assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); - assertEquals(dmaapMRSubscriberResponse.getResponseMessage(), "Test Message"); - assertThat(dmaapMRSubscriberResponse.getFetchedMessages().size(), is(0)); - - } - - //endregion -} - - - - - diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java deleted file mode 100644 index a24bb39..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.impl.client.CloseableHttpClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; - -import java.io.IOException; -import java.util.ArrayList; - -import static org.hamcrest.CoreMatchers.isA; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * @author Rajiv Singla. Creation Date: 10/21/2016. - */ -@RunWith(MockitoJUnitRunner.class) -public class DMaaPMRPublisherImplTest extends BaseAnalyticsDMaaPUnitTest { - - @Mock - DMaaPMRPublisherQueueFactory dmaapMRPublisherQueueFactory; - @Mock - CloseableHttpClient closeableHttpClient; - @Mock - DMaaPMRPublisherQueue dmaapMRPublisherQueue; - - @Before - public void setUp() throws Exception { - given(dmaapMRPublisherQueueFactory.create(Mockito.anyInt(), Mockito.anyInt())) - .willReturn(dmaapMRPublisherQueue); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testPublishSmallMessageList() throws Exception { - given(dmaapMRPublisherQueue.getBatchQueueRemainingSize()).willReturn(10); - given(dmaapMRPublisherQueue.addBatchMessages(Mockito.anyList())).willReturn(2); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - - DMaaPMRPublisherResponse dmaapMRPublisherResponse = dmaapMRPublisherImpl.publish(getTwoSampleMessages()); - - assertThat(dmaapMRPublisherResponse.getResponseCode(), is(202)); - assertThat(dmaapMRPublisherResponse.getPendingMessagesCount(), is(2)); - assertThat(dmaapMRPublisherResponse.getResponseMessage(), - is("Accepted - Messages queued for batch publishing to MR Topic")); - } - - @Test - public void testPublishBigMessageList() throws Exception { - - given(dmaapMRPublisherQueue.getBatchQueueRemainingSize()).willReturn(0); - given(dmaapMRPublisherQueue.getMessageForPublishing()).willReturn(getTwoSampleMessages()); - Mockito.when( - closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - - DMaaPMRPublisherResponse dmaapMRPublisherResponse = dmaapMRPublisherImpl.publish(getTwoSampleMessages()); - - assertThat(dmaapMRPublisherResponse.getResponseCode(), is(200)); - assertThat(dmaapMRPublisherResponse.getPendingMessagesCount(), is(200)); - assertThat(dmaapMRPublisherResponse.getResponseMessage(), is("Message successfully posted")); - } - - @Test - public void testForcePublishSuccessful() throws Exception { - DMaaPMRPublisherConfig dmaapMRPublisherConfig = new - DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setProtocol(HTTP_PROTOCOL) - .setContentType(CONTENT_TYPE) - .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) - .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE).build(); - - HttpPost httpPost = Mockito.mock(HttpPost.class); - Mockito.when(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - dmaapMRPublisherConfig, dmaapMRPublisherQueueFactory, closeableHttpClient); - DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.forcePublish(getTwoSampleMessages()); - assertThat(response.getResponseCode(), is(200)); - } - - @Test - public void testForcePublishFailure() throws Exception { - Mockito.when(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(503, "Message successfully posted")); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.forcePublish(getTwoSampleMessages()); - assertThat(response.getResponseCode(), is(503)); - } - - @Rule - public ExpectedException httpIOException = ExpectedException.none(); - - @Test - public void testForcePublishHttpFailure() throws Exception { - - httpIOException.expect(DCAEAnalyticsRuntimeException.class); - httpIOException.expectCause(isA(IOException.class)); - - given(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).willThrow(IOException.class); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.forcePublish(getTwoSampleMessages()); - } - - @Test - public void testFlushSuccessful() throws Exception { - Mockito.when(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); - - Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(getTwoSampleMessages()); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.flush(); - assertThat(response.getResponseCode(), is(200)); - } - - @Test - public void testFlushEmptyList() throws Exception { - Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(new ArrayList()); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.flush(); - assertThat(response.getResponseCode(), is(204)); - } - - @Test - public void testClose() throws Exception { - Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(new ArrayList()); - Mockito.when(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); - Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(getTwoSampleMessages()); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - dmaapMRPublisherImpl.close(); - verify(closeableHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)); - } - - @Test - public void testCloseUnsuccessful() throws Exception { - Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(new ArrayList()); - Mockito.when(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(400, "Message successfully posted")); - Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(getTwoSampleMessages()); - - DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( - getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); - dmaapMRPublisherImpl.close(); - verify(closeableHttpClient, times(6)).execute(Mockito.any(HttpUriRequest.class), - Mockito.any(ResponseHandler.class)); - } -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java deleted file mode 100644 index 333b816..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRPublisherResponseImpl; - -import java.util.Date; -import java.util.List; - -/** - * @author Rajiv Singla. Creation Date: 10/21/2016. - */ -public class DMaaPMRPublisherMockImpl implements DMaaPMRPublisher { - - @Override - public DMaaPMRPublisherResponse publish(List messages) throws DCAEAnalyticsRuntimeException { - return new DMaaPMRPublisherResponseImpl(102, "Mock Response", 100); - } - - @Override - public DMaaPMRPublisherResponse forcePublish(List messages) throws DCAEAnalyticsRuntimeException { - return null; - } - - @Override - public DMaaPMRPublisherResponse flush() { - return null; - } - - @Override - public Date getPublisherCreationTime() { - return null; - } - - @Override - public void close() throws Exception { - - } -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java deleted file mode 100644 index 07622df..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import org.junit.Test; -import org.openecomp.dcae.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; - -import java.util.List; - -import static org.junit.Assert.assertTrue; - -/** - * - * @author Rajiv Singla. Creation Date: 11/2/2016. - */ -public class DMaaPMRPublisherQueueImplTest extends BaseAnalyticsDMaaPUnitTest { - - - @Test - public void testAddBatchMessages() throws Exception { - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - // add two more message to batch queue - final int batchMessagesSizeAfterSecondInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 4", batchMessagesSizeAfterSecondInsert == 4); - // Now get all messages which must drain out batch queue - final List messagesToPublish = publisherQueue.getMessageForPublishing(); - assertTrue("There must be 4 messages to publish", messagesToPublish.size() == 4); - assertTrue("Batch Queue must be empty", publisherQueue.getBatchQueueRemainingSize() == 10); - - } - - @Test(expected = IllegalStateException.class) - public void testAddBatchMessagesWhenQueueSizeIsFull() throws Exception { - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(2, 20); - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - // add 2 more messages should now throw IllegalStateException - publisherQueue.addBatchMessages(getTwoSampleMessages()); - } - - @Test - public void testAddRecoverableMessages() throws Exception { - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - // add two recoverable messages - final int recoverableMessageSizeAfterFirstInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 2 after first insert", - recoverableMessageSizeAfterFirstInsert == 2); - // add two more recoverable messages - final int recoverableMessageSizeAfterSecondInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 4 after second insert", - recoverableMessageSizeAfterSecondInsert == 4); - // Now get all messages which must drain out batch queue - final List messagesToPublish = publisherQueue.getMessageForPublishing(); - assertTrue("There must be 6 messages to publish", messagesToPublish.size() == 6); - assertTrue("Batch Queue must be empty", publisherQueue.getBatchQueueRemainingSize() == 10); - assertTrue("Recovery Queue must be empty", publisherQueue.getRecoveryQueueRemainingSize() == 20); - } - - - @Test(expected = IllegalStateException.class) - public void testAddRecoverableMessagesWhenRecoveryQueueIsFull() throws Exception { - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 2); - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - // add two recoverable messages - final int recoverableMessageSizeAfterFirstInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 2 after first insert", - recoverableMessageSizeAfterFirstInsert == 2); - // add two more recoverable messages which should throw IllegalStateException - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - } - - @Test - public void testGetMessageForPublishing() throws Exception { - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - // add two recoverable messages - final int recoverableMessageSizeAfterFirstInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 2 after first insert", - recoverableMessageSizeAfterFirstInsert == 2); - // add two more recoverable messages - final int recoverableMessageSizeAfterSecondInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 4 after second insert", - recoverableMessageSizeAfterSecondInsert == 4); - // Now get all messages which must drain out batch queue - final List messagesToPublish = publisherQueue.getMessageForPublishing(); - assertTrue("There must be 6 messages to publish", messagesToPublish.size() == 6); - // add two more batch and recovery messages - final int batchQueueSize = publisherQueue.addBatchMessages(getTwoSampleMessages()); - final int recoveryQueueSize = publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - final int messagePublishCount = publisherQueue.getMessageForPublishing().size(); - assertTrue("Batch Queue + Recovery Queue message total must batch publish message count", - messagePublishCount == (batchQueueSize + recoveryQueueSize)); - assertTrue("Batch Queue must be empty", publisherQueue.getBatchQueueRemainingSize() == 10); - assertTrue("Recovery Queue must be empty", publisherQueue.getRecoveryQueueRemainingSize() == 20); - - } - - @Test - public void testGetBatchQueueRemainingSize() throws Exception { - - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - assertTrue("Batch remaining capacity should be reduced by 2", - publisherQueue.getBatchQueueRemainingSize() == 8); - - // add two recoverable messages - final int recoverableMessageSizeAfterFirstInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 2 after first insert", - recoverableMessageSizeAfterFirstInsert == 2); - - // recoverable message should not change batch queue capacity - assertTrue("Adding recoverable Message must not have any impact on batch queue remaining capacity ", - publisherQueue.getBatchQueueRemainingSize() == 8); - // Now get all messages which must drain out batch queue - final List messagesToPublish = publisherQueue.getMessageForPublishing(); - assertTrue("There must be exactly 4 messages to publish", messagesToPublish.size() == 4); - - // Batch queue remaining capacity should now match original batch size - assertTrue("Batch Queue remaining capacity must match original batch queue size", publisherQueue - .getBatchQueueRemainingSize() == 10); - } - - @Test - public void testGetRecoveryQueueRemainingSize() throws Exception { - DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); - - // add two recoverable messages - final int recoverableMessageSizeAfterFirstInsert = - publisherQueue.addRecoverableMessages(getTwoSampleMessages()); - assertTrue("Recovery Message Queue size must be 2 after first insert", - recoverableMessageSizeAfterFirstInsert == 2); - assertTrue("Recovery Queue remaining capacity should be reduced by 2", - publisherQueue.getRecoveryQueueRemainingSize() == 18); - - // add two messages to batch queue - final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); - assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); - - // batch message should not change recoverable queue capacity - assertTrue("Adding batch queue Message must not have any impact on recovery queue remaining capacity ", - publisherQueue.getRecoveryQueueRemainingSize() == 18); - - // Now get all messages which must drain out recovery queue - final List messagesToPublish = publisherQueue.getMessageForPublishing(); - assertTrue("There must be exactly 4 messages to publish", messagesToPublish.size() == 4); - - // Recoverable queue remaining capacity should now match original recovery queue size - assertTrue("Recoverable Queue remaining capacity must match original batch queue size", publisherQueue - .getRecoveryQueueRemainingSize() == 20); - } - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java deleted file mode 100644 index 585d0ba..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.publisher; - -import java.util.List; - -/** - * @author Manjesh Gowda. Creation Date: 11/7/2016. - */ -public class DMaaPMRPublisherQueueMockImpl implements DMaaPMRPublisherQueue { - @Override - public int addBatchMessages(List batchMessages) throws IllegalStateException { - return 100; - } - - @Override - public int addRecoverableMessages(List recoverableMessages) throws IllegalStateException { - return 0; - } - - @Override - public List getMessageForPublishing() { - return null; - } - - @Override - public int getBatchQueueRemainingSize() { - return 0; - } - - @Override - public int getRecoveryQueueRemainingSize() { - return 0; - } -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java deleted file mode 100644 index 6d8c79a..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.subscriber; - -import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.impl.client.CloseableHttpClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; -import org.openecomp.dcae.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; - -import java.io.IOException; -import java.util.Random; -import java.util.UUID; - -import static org.hamcrest.CoreMatchers.isA; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.mockito.BDDMockito.given; - -/** - * @author Rajiv Singla. Creation Date: 10/21/2016. - */ -@RunWith(MockitoJUnitRunner.class) -public class DMaaPMRSubscriberImplTest extends BaseAnalyticsDMaaPUnitTest { - - @Mock - CloseableHttpClient closeableHttpClient; - - private String consumerGroup, consumerId; - - @Before - public void setUp() throws Exception { - Random random = new Random(10000L); - consumerGroup = "Test-Consumer-Group" + Long.toString(random.nextLong()); - consumerId = UUID.randomUUID().toString(); - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testSubscriberSuccessfullyReceiveDmaapMessage() throws Exception { - - String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," + - "{\"message\":\"I'm Object 2 Message\"}]"; - Mockito.when( - closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, testMessages)); - - DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( - getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); - assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); - assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2)); - } - - @Test - public void testSubscriberSuccessfullyReceiveDmaapMessageWithNoUsername() throws Exception { - - DMaaPMRSubscriberConfig dmaapMRSubscriberConfig = new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) - .setPortNumber(PORT_NUMBER) - .setProtocol(HTTP_PROTOCOL) - .setContentType(CONTENT_TYPE) - .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME) - .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID) - .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) - .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build(); - - String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," + - "{\"message\":\"I'm Object 2 Message\"}]"; - Mockito.when( - closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, testMessages)); - - DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( - dmaapMRSubscriberConfig, closeableHttpClient); - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); - assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); - assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2)); - } - - @Test - public void testSubscriberSuccessfullyReceiveNoDmaapMessage() throws Exception { - Mockito.when( - closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(200, null)); - - DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( - getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); - assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); - assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0)); - } - - @Test - public void testSubscriberSuccessfullyReceiveErrorMessage() throws Exception { - Mockito.when( - closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) - .thenReturn(new ImmutablePair<>(400, "Bad Request")); - - DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( - getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); - assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(400)); - assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0)); - } - - @Rule - public ExpectedException httpIOException = ExpectedException.none(); - - @Test - public void testSubscriberSuccessfullyReceiveException() throws Exception { - - httpIOException.expect(DCAEAnalyticsRuntimeException.class); - httpIOException.expectCause(isA(IOException.class)); - - given(closeableHttpClient.execute( - Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).willThrow(IOException.class); - - DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( - getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); - DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); - } - -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java deleted file mode 100644 index 87a76d0..0000000 --- a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ============LICENSE_START========================================================= - * dcae-analytics - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.dcae.analytics.dmaap.service.subscriber; - -import org.openecomp.dcae.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.analytics.dmaap.domain.response.DMaaPMRSubscriberResponseImpl; - -import java.util.Date; - -/** - * @author Rajiv Singla. Creation Date: 10/21/2016. - */ -public class DMaaPMRSubscriberMockImpl implements DMaaPMRSubscriber { - - @Override - public DMaaPMRSubscriberResponse fetchMessages() throws DCAEAnalyticsRuntimeException { - return new DMaaPMRSubscriberResponseImpl(102, "Mock Response", null); - } - - @Override - public Date getSubscriberCreationTime() { - return null; - } - - @Override - public void close() throws Exception { - - } -} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java new file mode 100644 index 0000000..133cf84 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPGuiceUnitTest.java @@ -0,0 +1,31 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap; + +import org.junit.runner.RunWith; +import org.openecomp.dcae.apod.analytics.test.runner.GuiceJUnitRunner; + +/** + * @author Rajiv Singla. Creation Date: 10/20/2016. + */ +@RunWith(GuiceJUnitRunner.class) +public abstract class BaseAnalyticsDMaaPGuiceUnitTest extends BaseAnalyticsDMaaPUnitTest { +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java new file mode 100644 index 0000000..c9c07a7 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/BaseAnalyticsDMaaPUnitTest.java @@ -0,0 +1,99 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap; + +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest; + +import java.util.List; + +import static com.google.common.collect.ImmutableList.of; + +/** + * @author Rajiv Singla. Creation Date: 10/14/2016. + */ +public abstract class BaseAnalyticsDMaaPUnitTest extends BaseDCAEAnalyticsUnitTest { + + // Unit Test Settings + protected static final String HOST_NAME = "testHostName"; + protected static final Integer PORT_NUMBER = 8080; + protected static final String TOPIC_NAME = "testTopicName"; + protected static final String USERNAME = "testUserName"; + protected static final String PASSWORD = "testPassword"; + protected static final String HTTP_PROTOCOL = "https"; + protected static final String CONTENT_TYPE = "application/json"; + + protected static final int PUBLISHER_MAX_BATCH_QUEUE_SIZE = 200; + protected static final int PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 2000; + + protected static final String SUBSCRIBER_CONSUMER_ID = "123"; + protected static final String SUBSCRIBER_CONSUMER_GROUP_NAME = "testGonsumerName-" + SUBSCRIBER_CONSUMER_ID; + protected static final int SUBSCRIBER_TIMEOUT_MS = 2000; + protected static final int SUBSCRIBER_MESSAGE_LIMIT = 20; + + /** + * Creates Sample Publisher settings for unit testing purposes + * + * @return sample publisher settings for testing + */ + protected static DMaaPMRPublisherConfig getPublisherConfig() { + return new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setProtocol(HTTP_PROTOCOL) + .setUserName(USERNAME) + .setUserPassword(PASSWORD) + .setContentType(CONTENT_TYPE) + .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) + .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE).build(); + } + + /** + * Creates Sample Subscriber settings for unit testing purposes + * + * @return sample subscriber settings for testing + */ + protected static DMaaPMRSubscriberConfig getSubscriberConfig(String consumerId, String consumerGroup) { + return new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setUserName(USERNAME) + .setUserPassword(PASSWORD) + .setProtocol(HTTP_PROTOCOL) + .setContentType(CONTENT_TYPE) + .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME) + .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID) + .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) + .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build(); + } + + /** + * Creates two sample message for publishing + * + * @return sample publish message list + */ + protected static List getTwoSampleMessages() { + String message1 = "{ \"message\" : \"Test Message1\"}"; + String message2 = "{ \"message\" : \"Test Message2\"}"; + return of(message1, message2); + } + + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactoryTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactoryTest.java new file mode 100644 index 0000000..38f6381 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/DMaaPMRFactoryTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.openecomp.dcae.apod.analytics.dmaap.module.AnalyticsDMaaPTestModule; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; +import org.openecomp.dcae.apod.analytics.test.annotation.GuiceModules; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Manjesh Gowda. Creation Date: 11/7/2016. + */ +@GuiceModules(AnalyticsDMaaPTestModule.class) +public class DMaaPMRFactoryTest extends BaseAnalyticsDMaaPGuiceUnitTest { + + private DMaaPMRFactory dmaapMRFactory; + + @Before + public void setUp() throws Exception { + dmaapMRFactory = new DMaaPMRFactory(new AnalyticsDMaaPTestModule()); + } + + @Test + public void createPublisher() throws Exception { + DMaaPMRPublisher publisher = dmaapMRFactory.createPublisher(getPublisherConfig()); + DMaaPMRPublisherResponse response = publisher.publish(null); + assertThat(response.getResponseCode(), is(102)); + } + + @Test + public void createSubscriber() throws Exception { + DMaaPMRSubscriber dmaapMRSubscriber = dmaapMRFactory.createSubscriber(getSubscriberConfig("", "")); + DMaaPMRSubscriberResponse response = dmaapMRSubscriber.fetchMessages(); + assertThat(response.getResponseCode(), is(102)); + } + + @Test + public void create() throws Exception { + + } + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java new file mode 100644 index 0000000..4699700 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRPublisherConfigTest.java @@ -0,0 +1,86 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.config; + +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; + +import static org.junit.Assert.assertTrue; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_CONTENT_TYPE; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PORT_NUMBER; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PROTOCOL; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_USER_NAME; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_USER_PASSWORD; + +/** + * @author Rajiv Singla. Creation Date: 10/14/2016. + */ +public class DMaaPMRPublisherConfigTest extends BaseAnalyticsDMaaPUnitTest { + + + @Test + public void testPublisherConfigDefaults() throws Exception { + + final DMaaPMRPublisherConfig actualDefaultPublisherConfig = + new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME).build(); + + final DMaaPMRPublisherConfig expectedDefaultPublisherConfig = + new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(DEFAULT_PORT_NUMBER) + .setUserName(DEFAULT_USER_NAME) + .setUserPassword(DEFAULT_USER_PASSWORD) + .setContentType(DEFAULT_CONTENT_TYPE) + .setProtocol(DEFAULT_PROTOCOL) + .setMaxBatchSize(DEFAULT_PUBLISHER_MAX_BATCH_SIZE) + .setMaxRecoveryQueueSize(DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) + .build(); + + assertTrue("Default Publisher Config parameters must match", + actualDefaultPublisherConfig.equals(expectedDefaultPublisherConfig)); + + } + + + @Test + public void testPublisherCustomConfig() throws Exception { + + + final DMaaPMRPublisherConfig actualCustomPublisherConfig = getPublisherConfig(); + + final DMaaPMRPublisherConfig expectedCustomPublisherConfig = + new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setUserName(USERNAME) + .setUserPassword(PASSWORD) + .setContentType(CONTENT_TYPE) + .setProtocol(HTTP_PROTOCOL) + .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE) + .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) + .build(); + + assertTrue("Custom Publisher Config parameters must match", + actualCustomPublisherConfig.equals(expectedCustomPublisherConfig)); + } + + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java new file mode 100644 index 0000000..4490c6f --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/domain/config/DMaaPMRSubscriberConfigTest.java @@ -0,0 +1,91 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.domain.config; + +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; + +import static org.junit.Assert.assertTrue; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_GROUP_PREFIX; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_MESSAGE_LIMIT; +import static org.openecomp.dcae.apod.analytics.common.AnalyticsConstants.DEFAULT_SUBSCRIBER_TIMEOUT_MS; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_CONTENT_TYPE; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PORT_NUMBER; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_PROTOCOL; +import static org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRConfig.DEFAULT_USER_NAME; + +/** + * @author Rajiv Singla. Creation Date: 10/14/2016. + */ +public class DMaaPMRSubscriberConfigTest extends BaseAnalyticsDMaaPUnitTest { + + @Test + public void testSubscriberConfigDefaults() throws Exception { + + DMaaPMRSubscriberConfig actualDefaultSubscriberConfig = + new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) + .setConsumerGroup(DEFAULT_SUBSCRIBER_GROUP_PREFIX + SUBSCRIBER_CONSUMER_ID) + .setConsumerId(SUBSCRIBER_CONSUMER_ID).build(); + + DMaaPMRSubscriberConfig expectedSubscriberConfig = + new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(DEFAULT_PORT_NUMBER) + .setUserName(DEFAULT_USER_NAME) + .setContentType(DEFAULT_CONTENT_TYPE) + .setProtocol(DEFAULT_PROTOCOL) + .setConsumerGroup(DEFAULT_SUBSCRIBER_GROUP_PREFIX + SUBSCRIBER_CONSUMER_ID) + .setConsumerId(SUBSCRIBER_CONSUMER_ID) + .setMessageLimit(DEFAULT_SUBSCRIBER_MESSAGE_LIMIT) + .setTimeoutMS(DEFAULT_SUBSCRIBER_TIMEOUT_MS) + .build(); + + assertTrue("Default Subscriber Config parameters must match", + actualDefaultSubscriberConfig.equals(expectedSubscriberConfig)); + + } + + + @Test + public void testSubscriberCustomConfig() throws Exception { + + DMaaPMRSubscriberConfig actualSubscriberCustomConfig = getSubscriberConfig(SUBSCRIBER_CONSUMER_ID, + SUBSCRIBER_CONSUMER_GROUP_NAME); + + DMaaPMRSubscriberConfig expectedSubscriberCustomConfig = + new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setUserName(USERNAME) + .setUserPassword(PASSWORD) + .setContentType(CONTENT_TYPE) + .setProtocol(HTTP_PROTOCOL) + .setConsumerGroup(SUBSCRIBER_CONSUMER_GROUP_NAME) + .setConsumerId(SUBSCRIBER_CONSUMER_ID) + .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT) + .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) + .build(); + + assertTrue("Custom Subscriber Config parameters must match", + actualSubscriberCustomConfig.equals(expectedSubscriberCustomConfig)); + + } + + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java new file mode 100644 index 0000000..d25fbad --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/BaseAnalyticsDMaaPIT.java @@ -0,0 +1,110 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.it; + +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; +import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsIT; + +import java.util.List; + +import static com.google.common.collect.ImmutableList.of; + +/** + * Base class for all DCAE DMaaP Integration Tests + *

+ * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public abstract class BaseAnalyticsDMaaPIT extends BaseDCAEAnalyticsIT { + + // Integration Test Settings + protected static final String HOST_NAME = "mrlocal-mtnjftle01.homer.com"; + protected static final Integer PORT_NUMBER = 3905; + protected static final String TOPIC_NAME = "com.dcae.dmaap.mtnje2.DcaeTestVESPub"; + + protected static final String USERNAME = "m00502@tca.af.dcae.com"; + protected static final String PASSWORD = "Te5021abc"; + protected static final String HTTP_PROTOCOL = "https"; + protected static final String CONTENT_TYPE = "application/json"; + + protected static final int PUBLISHER_MAX_BATCH_QUEUE_SIZE = 20; + protected static final int PUBLISHER_MAX_RECOVERY_QUEUE_SIZE = 200; + + protected static final String SUBSCRIBER_CONSUMER_ID = "123"; + protected static final String SUBSCRIBER_CONSUMER_GROUP_NAME = "testGonsumerName-" + SUBSCRIBER_CONSUMER_ID; + protected static final int SUBSCRIBER_TIMEOUT_MS = 2000; + protected static final int SUBSCRIBER_MESSAGE_LIMIT = 20; + + /** + * Creates Sample Publisher settings for integration testing purposes + * + * @return + */ + protected static DMaaPMRPublisherConfig getPublisherConfig() { + return new DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setProtocol(HTTP_PROTOCOL) + .setContentType(CONTENT_TYPE) + .setUserName(USERNAME) + .setUserPassword(PASSWORD) + .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE) + .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) + .build(); + } + + /** + * Creates Sample Subscriber settings for integration testing purposes + * + * @return + */ + protected static DMaaPMRSubscriberConfig getSubscriberConfig(String consumerId) { + return new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setProtocol(HTTP_PROTOCOL) + .setContentType(CONTENT_TYPE) + .setUserName(USERNAME) + .setUserPassword(PASSWORD) + .setConsumerGroup(SUBSCRIBER_CONSUMER_GROUP_NAME) + .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID) + .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) + .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build(); + } + + /** + * Publishes 2 sample message to DMaaP Topic for integration test purposes + * + * @param dMaaPMRPublisher + * @return + */ + protected static DMaaPMRPublisherResponse publishTwoSampleMessages(DMaaPMRPublisher dMaaPMRPublisher) { + DMaaPMRPublisherResponse dMaaPMRPublisherResponse = dMaaPMRPublisher.publish(getTwoSampleMessage()); + return dMaaPMRPublisherResponse; + } + + protected static List getTwoSampleMessage() { + String message1 = "{ \"message\" : \"Test Message1\"}"; + String message2 = "{ \"message\" : \"Test Message2\"}"; + return of(message1, message2); + } + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRPublisherImplIT.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRPublisherImplIT.java new file mode 100644 index 0000000..129e64c --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRPublisherImplIT.java @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.it; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; + +/** + * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public class DMaaPMRPublisherImplIT extends BaseAnalyticsDMaaPIT { + + private DMaaPMRPublisher dMaaPMRPublisher; + + @Before + public void before() throws Exception { + DMaaPMRFactory dMaaPMRFactory = DMaaPMRFactory.create(); + dMaaPMRPublisher = dMaaPMRFactory.createPublisher(getPublisherConfig()); + } + + @Test + public void testPublish() throws Exception { + long pendingMessageCount = publishTwoSampleMessages(dMaaPMRPublisher).getPendingMessagesCount(); + Assert.assertTrue("Published Message Count must be 2", pendingMessageCount == 2); + } + + @Test + public void testFlush() throws Exception { + publishTwoSampleMessages(dMaaPMRPublisher); + DMaaPMRPublisherResponse publisherResponse = dMaaPMRPublisher.flush(); + Integer responseCode = publisherResponse.getResponseCode(); + Assert.assertTrue("Server Response code must be 200", responseCode == 200); + } +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java new file mode 100644 index 0000000..6553dc7 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/it/DMaaPMRSubscriberImplIT.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.it; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.dmaap.DMaaPMRFactory; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; + +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.assertTrue; + +/** + * @author Rajiv Singla. Creation Date: 10/13/2016. + */ +public class DMaaPMRSubscriberImplIT extends BaseAnalyticsDMaaPIT { + + private DMaaPMRPublisher dMaaPMRPublisher; + private DMaaPMRSubscriber dMaaPMRSubscriber; + + @Before + public void before() throws Exception { + String randomConsumerID = UUID.randomUUID().toString(); + DMaaPMRFactory dMaaPMRFactory = DMaaPMRFactory.create(); + dMaaPMRSubscriber = dMaaPMRFactory.createSubscriber(getSubscriberConfig(randomConsumerID)); + dMaaPMRPublisher = dMaaPMRFactory.createPublisher(getPublisherConfig()); + } + + @After + public void after() throws Exception { + dMaaPMRSubscriber.close(); + dMaaPMRPublisher.close(); + } + + + @Test + public void testFetchMessages() throws Exception { + + // This call is used to just register a brand new subscriber with DMaaP + DMaaPMRSubscriberResponse subscriberRegistrationResponse = dMaaPMRSubscriber.fetchMessages(); + assertTrue("Subscriber Registration Response code must be 200 confirming subscriber was registered " + + "successfully", subscriberRegistrationResponse.getResponseCode() == 200); + assertTrue("Subscriber Registration Response must not contain any messages", subscriberRegistrationResponse + .getFetchedMessages().size() == 0); + + // Force push couple of test messages + DMaaPMRPublisherResponse publisherResponse = dMaaPMRPublisher.forcePublish(getTwoSampleMessage()); + assertTrue("Message must be posted successfully before subscriber can fetch it", publisherResponse + .getResponseCode() == 200); + + // Now fetch messages from DMaaP + DMaaPMRSubscriberResponse subscriberResponse = dMaaPMRSubscriber.fetchMessages(); + List messageList = new LinkedList<>(); + for (String message : subscriberResponse.getFetchedMessages()) { + messageList.add(message); + } + assertTrue("Subscriber message count must be 2", messageList.size() == 2); + } + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPTestModule.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPTestModule.java new file mode 100644 index 0000000..00ac232 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/module/AnalyticsDMaaPTestModule.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.module; + +import com.google.inject.AbstractModule; +import com.google.inject.assistedinject.FactoryModuleBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherMockImpl; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueueImpl; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriberFactory; +import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriberMockImpl; + +/** + * DMaaP Guice Test Module + *

+ * @author Rajiv Singla. Creation Date: 10/20/2016. + */ +public class AnalyticsDMaaPTestModule extends AbstractModule { + + + @Override + protected void configure() { +// Bind Http Client + bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault()); + + // Bind Publishing queue + install(new FactoryModuleBuilder().implement(DMaaPMRPublisherQueue.class, DMaaPMRPublisherQueueImpl.class) + .build(DMaaPMRPublisherQueueFactory.class)); + + install(new FactoryModuleBuilder().implement(DMaaPMRPublisher.class, DMaaPMRPublisherMockImpl.class) + .build(DMaaPMRPublisherFactory.class)); + + install(new FactoryModuleBuilder().implement(DMaaPMRSubscriber.class, DMaaPMRSubscriberMockImpl.class) + .build(DMaaPMRSubscriberFactory.class)); + } +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponentTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponentTest.java new file mode 100644 index 0000000..4edf91b --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/BaseDMaaPMRComponentTest.java @@ -0,0 +1,340 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.base.Optional; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; +import org.apache.http.client.ResponseHandler; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisherQueue; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isA; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +/** + * @author Manjesh Gowda. Creation Date: 11/4/2016. + */ +public class BaseDMaaPMRComponentTest extends BaseAnalyticsDMaaPUnitTest { + + //region Get Authorization Header Tests + @Test + public void testGetAuthHeaderWithGoodValues() { + String expectedEncodedString = "Basic bTAwNTAyQHRjYS5hZi5kY2FlLmNvbTpUZTUwMjFhYmM="; + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("m00502@tca.af.dcae.com", "Te5021abc"); + assertTrue(" Authentication Header has value ", actualOutput.isPresent()); + assertEquals(" Authentication Header has value ", expectedEncodedString, actualOutput.get()); + } + + @Test + public void testGetAuthHeaderWithNullValues() { + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader(null, null); + assertFalse(" Authentication Header has value ", actualOutput.isPresent()); + } + + @Test + public void testGetAuthHeaderWithUserNullValue() { + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("m00502@tca.af.dcae.com", null); + assertFalse(" Authentication Header has value ", actualOutput.isPresent()); + } + + @Test + public void testGetAuthHeaderWithPasswordNullValue() { + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader(null, "Te5021abc"); + assertFalse(" Authentication Header has value ", actualOutput.isPresent()); + } + + /* @Test + public void testGetAuthHeaderWithEmptyValues() { + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("", ""); + assertFalse(" Authentication Header has value ", actualOutput.isPresent()); + } + + @Test + public void testGetAuthHeaderWithUserEmptyValue() { + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("m00502@tca.af.dcae.com", ""); + assertFalse(" Authentication Header has value ", actualOutput.isPresent()); + } + + @Test + public void testGetAuthHeaderWithPasswordEmptyValue() { + Optional actualOutput = BaseDMaaPMRComponent.getAuthHeader("", "Te5021abc"); + assertFalse(" Authentication Header has value ", actualOutput.isPresent()); + }*/ + //endregion + + //region Publisher URI Tests + @Test + public void testCreatePublishURIWithGoodValues() { + URI actualURI = BaseDMaaPMRComponent.createPublisherURI(getPublisherConfig()); + String test = actualURI.toString(); + assertEquals("Generated Publisher URL is correct", + "https://testHostName:8080/events/testTopicName", actualURI.toString()); + } + + @Test(expected = DCAEAnalyticsRuntimeException.class) + public void testCreatePublishURIWithURISyntaxException() { + DMaaPMRPublisherConfig badPublisherConfig = new DMaaPMRPublisherConfig + .Builder(" dav /gh. ss/ asd ", "///@$%#-htps:<>!##") + .setPortNumber(0) + .setProtocol("https").build(); + + URI actualURI = BaseDMaaPMRComponent.createPublisherURI(badPublisherConfig); + } + + //endregion + + //region Subscriber URI Tests + @Test + public void testCreateSubscribeURIWithGoodValues() { + URI actualURI = BaseDMaaPMRComponent.createSubscriberURI( + getSubscriberConfig("test-consumer-group", "test-consumer-id")); + assertEquals("Generated Subscriber URL is correct", + "https://testHostName:8080/events/testTopicName/" + + "test-consumer-id/test-consumer-group?timeout=2000&limit=20", + actualURI.toString()); + } + + @Test(expected = DCAEAnalyticsRuntimeException.class) + public void testCreateSubscribeURIWithURISyntaxException() { + DMaaPMRSubscriberConfig badSubscriberConfig = new DMaaPMRSubscriberConfig + .Builder(" dav /gh. ss/ asd ", "") + .setPortNumber(PORT_NUMBER) + .setProtocol(HTTP_PROTOCOL) + .setContentType(CONTENT_TYPE).build(); + + URI actualURI = BaseDMaaPMRComponent.createSubscriberURI(badSubscriberConfig); + } + + //endregion + + //region Convert toJSON String tests + @Test + public void testConvertToJsonStringGoodJsonStringList() { + List jsonMessage = Arrays.asList( + "{\"message\":\"I'm Object 1 Message\"}", + "{\"message\":\"I'm Object 2 Message\"}"); + + String actualJSONMsg = BaseDMaaPMRComponent.convertToJsonString(jsonMessage); + + String expectedJSONMsg = "[{\"message\":\"I'm Object 1 Message\"}," + + "{\"message\":\"I'm Object 2 Message\"}]"; + assertEquals("Convert a List of Strings to JSON is working fine", expectedJSONMsg, actualJSONMsg); + + } + + @Rule + public ExpectedException expectedJsonProcessingException = ExpectedException.none(); + + @Test + public void testConvertToJsonStringBadJsonStringList() { + expectedJsonProcessingException.expect(DCAEAnalyticsRuntimeException.class); + expectedJsonProcessingException.expectCause(isA(JsonProcessingException.class)); + + List jsonMessage = Arrays.asList( + "{\"message\":\"I'm Object 1 Message\"", + "\"message\":\"I'm Object 2 Message\""); + + BaseDMaaPMRComponent.convertToJsonString(jsonMessage); + } + + @Test + public void testConvertToJsonStringWithEmptyList() { + List jsonMessage = Arrays.asList(); + String actualJSONMsg = BaseDMaaPMRComponent.convertToJsonString(jsonMessage); + String expectedJSONMsg = "[]"; + assertEquals("Convert a List of Strings to JSON is working fine", expectedJSONMsg, actualJSONMsg); + } + + @Test + public void testConvertToJsonStringWithNullList() { + String actualJSONMsg = BaseDMaaPMRComponent.convertToJsonString(null); + String expectedJSONMsg = "[]"; + assertEquals("Convert a List of Strings to JSON is working fine", expectedJSONMsg, actualJSONMsg); + } + + //endregion + + //region Convert JSONtoString String tests + + @Test + public void testConvertJsonToStringMessagesGoodValues() { + String inputJSONMsg = "[{\"message\":\"I'm Object 1 Message\"}," + + "{\"message\":\"I'm Object 2 Message\"}]"; + List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(inputJSONMsg); + assertThat(actualList, hasSize(2)); + assertThat(actualList, containsInAnyOrder( + "{\"message\":\"I'm Object 1 Message\"}", + "{\"message\":\"I'm Object 2 Message\"}" + )); + } + + @Test + public void testConvertJsonToStringMessagesNoValues() { + String inputJSONMsg = "[]"; + List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(inputJSONMsg); + assertThat(actualList, hasSize(0)); + } + + @Test + public void testConvertJsonToStringMessagesNullValues() { + List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(null); + assertThat(actualList, hasSize(0)); + } + + @Test + public void testConvertJsonToStringMessagesEmptyValues() { + List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(" "); + assertThat(actualList, hasSize(0)); + } + + @Rule + public ExpectedException convertToJSONIOException = ExpectedException.none(); + + @Test + public void testConvertJsonToStringMessagesException() { + convertToJSONIOException.expect(DCAEAnalyticsRuntimeException.class); + convertToJSONIOException.expectCause(isA(IOException.class)); + + String inputJSONMsg = "[\"{\"message\":\"I'm Object 1 Message\"}\"," + + "\"{\"message\":\"I'm Object 2 Message\"}\"]"; + List actualList = BaseDMaaPMRComponent.convertJsonToStringMessages(inputJSONMsg); + assertThat(actualList, hasSize(2)); + assertThat(actualList, containsInAnyOrder( + "{\"message\":\"I'm Object 1 Message\"}", + "{\"message\":\"I'm Object 2 Message\"}" + )); + } + + //endregion + + //region Test add message to recovery queue + @Test + public void testAddMessagesToRecoveryQueueAllGood() { + DMaaPMRPublisherQueue dmaapMRPublisherQueue = mock(DMaaPMRPublisherQueue.class); + given(dmaapMRPublisherQueue.addRecoverableMessages(Mockito.anyList())).willReturn(0); + given(dmaapMRPublisherQueue.getBatchQueueRemainingSize()).willReturn(0); + List messages = new ArrayList(); + BaseDMaaPMRComponent.addMessagesToRecoveryQueue(dmaapMRPublisherQueue, messages); + } + + @Rule + public ExpectedException addQueueIllegalException = ExpectedException.none(); + + @Test + public void testAddMessagesToRecoveryQueueException() { + addQueueIllegalException.expect(isA(DCAEAnalyticsRuntimeException.class)); + addQueueIllegalException.expectCause(isA(IllegalStateException.class)); + + DMaaPMRPublisherQueue dmaapMRPublisherQueue = mock(DMaaPMRPublisherQueue.class); + + given(dmaapMRPublisherQueue.addRecoverableMessages(Mockito.anyList())) + .willThrow(IllegalStateException.class); + List messages = new ArrayList(); + + BaseDMaaPMRComponent.addMessagesToRecoveryQueue(dmaapMRPublisherQueue, messages); + } + + //endregion + + //region Miscellaneous tests + + @Test + public void testResponseHandler() { + HttpResponse mockHttpResponse = mock(HttpResponse.class); + StatusLine mockStatusLine = mock(StatusLine.class); + HttpEntity mockHttpEntity = mock(HttpEntity.class); + // Could not mock EntityUtils as it's final class + //EntityUtils mockEntityUtils = mock(EntityUtils.class); + + given(mockHttpResponse.getStatusLine()).willReturn(mockStatusLine); + given(mockStatusLine.getStatusCode()).willReturn(200); + given(mockHttpResponse.getEntity()).willReturn(null); + //given(mockEntityUtils.toString()).willReturn("Test value"); + + ResponseHandler> responseHandler = BaseDMaaPMRComponent.responseHandler(); + try { + Pair mappedResponse = responseHandler.handleResponse(mockHttpResponse); + assertTrue("Http response code returned properly ", mappedResponse.getLeft().equals(200)); + assertTrue("Http response body returned properly ", mappedResponse.getRight().equals("")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + //endregion + + //region createSubscriberResponse tests + @Test + public void testCreateSubscriberResponse() { + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = + BaseDMaaPMRComponent.createSubscriberResponse(200, "Test Message", getTwoSampleMessages()); + + assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); + assertEquals(dmaapMRSubscriberResponse.getResponseMessage(), "Test Message"); + assertThat(dmaapMRSubscriberResponse.getFetchedMessages().size(), is(2)); + + } + + @Test + public void testCreateSubscriberResponse_no_message() { + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = + BaseDMaaPMRComponent.createSubscriberResponse(200, "Test Message", null); + + assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); + assertEquals(dmaapMRSubscriberResponse.getResponseMessage(), "Test Message"); + assertThat(dmaapMRSubscriberResponse.getFetchedMessages().size(), is(0)); + + } + + //endregion +} + + + + + diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java new file mode 100644 index 0000000..e037ceb --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherImplTest.java @@ -0,0 +1,212 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; + +import java.io.IOException; +import java.util.ArrayList; + +import static org.hamcrest.CoreMatchers.isA; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * @author Rajiv Singla. Creation Date: 10/21/2016. + */ +@RunWith(MockitoJUnitRunner.class) +public class DMaaPMRPublisherImplTest extends BaseAnalyticsDMaaPUnitTest { + + @Mock + DMaaPMRPublisherQueueFactory dmaapMRPublisherQueueFactory; + @Mock + CloseableHttpClient closeableHttpClient; + @Mock + DMaaPMRPublisherQueue dmaapMRPublisherQueue; + + @Before + public void setUp() throws Exception { + given(dmaapMRPublisherQueueFactory.create(Mockito.anyInt(), Mockito.anyInt())) + .willReturn(dmaapMRPublisherQueue); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testPublishSmallMessageList() throws Exception { + given(dmaapMRPublisherQueue.getBatchQueueRemainingSize()).willReturn(10); + given(dmaapMRPublisherQueue.addBatchMessages(Mockito.anyList())).willReturn(2); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + + DMaaPMRPublisherResponse dmaapMRPublisherResponse = dmaapMRPublisherImpl.publish(getTwoSampleMessages()); + + assertThat(dmaapMRPublisherResponse.getResponseCode(), is(202)); + assertThat(dmaapMRPublisherResponse.getPendingMessagesCount(), is(2)); + assertThat(dmaapMRPublisherResponse.getResponseMessage(), + is("Accepted - Messages queued for batch publishing to MR Topic")); + } + + @Test + public void testPublishBigMessageList() throws Exception { + + given(dmaapMRPublisherQueue.getBatchQueueRemainingSize()).willReturn(0); + given(dmaapMRPublisherQueue.getMessageForPublishing()).willReturn(getTwoSampleMessages()); + Mockito.when( + closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + + DMaaPMRPublisherResponse dmaapMRPublisherResponse = dmaapMRPublisherImpl.publish(getTwoSampleMessages()); + + assertThat(dmaapMRPublisherResponse.getResponseCode(), is(200)); + assertThat(dmaapMRPublisherResponse.getPendingMessagesCount(), is(200)); + assertThat(dmaapMRPublisherResponse.getResponseMessage(), is("Message successfully posted")); + } + + @Test + public void testForcePublishSuccessful() throws Exception { + DMaaPMRPublisherConfig dmaapMRPublisherConfig = new + DMaaPMRPublisherConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setProtocol(HTTP_PROTOCOL) + .setContentType(CONTENT_TYPE) + .setMaxRecoveryQueueSize(PUBLISHER_MAX_RECOVERY_QUEUE_SIZE) + .setMaxBatchSize(PUBLISHER_MAX_BATCH_QUEUE_SIZE).build(); + + HttpPost httpPost = Mockito.mock(HttpPost.class); + Mockito.when(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + dmaapMRPublisherConfig, dmaapMRPublisherQueueFactory, closeableHttpClient); + DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.forcePublish(getTwoSampleMessages()); + assertThat(response.getResponseCode(), is(200)); + } + + @Test + public void testForcePublishFailure() throws Exception { + Mockito.when(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(503, "Message successfully posted")); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.forcePublish(getTwoSampleMessages()); + assertThat(response.getResponseCode(), is(503)); + } + + @Rule + public ExpectedException httpIOException = ExpectedException.none(); + + @Test + public void testForcePublishHttpFailure() throws Exception { + + httpIOException.expect(DCAEAnalyticsRuntimeException.class); + httpIOException.expectCause(isA(IOException.class)); + + given(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).willThrow(IOException.class); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.forcePublish(getTwoSampleMessages()); + } + + @Test + public void testFlushSuccessful() throws Exception { + Mockito.when(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); + + Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(getTwoSampleMessages()); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.flush(); + assertThat(response.getResponseCode(), is(200)); + } + + @Test + public void testFlushEmptyList() throws Exception { + Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(new ArrayList()); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + DMaaPMRPublisherResponse response = dmaapMRPublisherImpl.flush(); + assertThat(response.getResponseCode(), is(204)); + } + + @Test + public void testClose() throws Exception { + Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(new ArrayList()); + Mockito.when(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, "Message successfully posted")); + Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(getTwoSampleMessages()); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + dmaapMRPublisherImpl.close(); + verify(closeableHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class)); + } + + @Test + public void testCloseUnsuccessful() throws Exception { + Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(new ArrayList()); + Mockito.when(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(400, "Message successfully posted")); + Mockito.when(dmaapMRPublisherQueue.getMessageForPublishing()).thenReturn(getTwoSampleMessages()); + + DMaaPMRPublisherImpl dmaapMRPublisherImpl = new DMaaPMRPublisherImpl( + getPublisherConfig(), dmaapMRPublisherQueueFactory, closeableHttpClient); + dmaapMRPublisherImpl.close(); + verify(closeableHttpClient, times(6)).execute(Mockito.any(HttpUriRequest.class), + Mockito.any(ResponseHandler.class)); + } +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java new file mode 100644 index 0000000..abd8618 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherMockImpl.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponse; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRPublisherResponseImpl; + +import java.util.Date; +import java.util.List; + +/** + * @author Rajiv Singla. Creation Date: 10/21/2016. + */ +public class DMaaPMRPublisherMockImpl implements DMaaPMRPublisher { + + @Override + public DMaaPMRPublisherResponse publish(List messages) throws DCAEAnalyticsRuntimeException { + return new DMaaPMRPublisherResponseImpl(102, "Mock Response", 100); + } + + @Override + public DMaaPMRPublisherResponse forcePublish(List messages) throws DCAEAnalyticsRuntimeException { + return null; + } + + @Override + public DMaaPMRPublisherResponse flush() { + return null; + } + + @Override + public Date getPublisherCreationTime() { + return null; + } + + @Override + public void close() throws Exception { + + } +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java new file mode 100644 index 0000000..7a24fa8 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueImplTest.java @@ -0,0 +1,189 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; + +import java.util.List; + +import static org.junit.Assert.assertTrue; + +/** + * + * @author Rajiv Singla. Creation Date: 11/2/2016. + */ +public class DMaaPMRPublisherQueueImplTest extends BaseAnalyticsDMaaPUnitTest { + + + @Test + public void testAddBatchMessages() throws Exception { + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + // add two more message to batch queue + final int batchMessagesSizeAfterSecondInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 4", batchMessagesSizeAfterSecondInsert == 4); + // Now get all messages which must drain out batch queue + final List messagesToPublish = publisherQueue.getMessageForPublishing(); + assertTrue("There must be 4 messages to publish", messagesToPublish.size() == 4); + assertTrue("Batch Queue must be empty", publisherQueue.getBatchQueueRemainingSize() == 10); + + } + + @Test(expected = IllegalStateException.class) + public void testAddBatchMessagesWhenQueueSizeIsFull() throws Exception { + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(2, 20); + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + // add 2 more messages should now throw IllegalStateException + publisherQueue.addBatchMessages(getTwoSampleMessages()); + } + + @Test + public void testAddRecoverableMessages() throws Exception { + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + // add two recoverable messages + final int recoverableMessageSizeAfterFirstInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 2 after first insert", + recoverableMessageSizeAfterFirstInsert == 2); + // add two more recoverable messages + final int recoverableMessageSizeAfterSecondInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 4 after second insert", + recoverableMessageSizeAfterSecondInsert == 4); + // Now get all messages which must drain out batch queue + final List messagesToPublish = publisherQueue.getMessageForPublishing(); + assertTrue("There must be 6 messages to publish", messagesToPublish.size() == 6); + assertTrue("Batch Queue must be empty", publisherQueue.getBatchQueueRemainingSize() == 10); + assertTrue("Recovery Queue must be empty", publisherQueue.getRecoveryQueueRemainingSize() == 20); + } + + + @Test(expected = IllegalStateException.class) + public void testAddRecoverableMessagesWhenRecoveryQueueIsFull() throws Exception { + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 2); + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + // add two recoverable messages + final int recoverableMessageSizeAfterFirstInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 2 after first insert", + recoverableMessageSizeAfterFirstInsert == 2); + // add two more recoverable messages which should throw IllegalStateException + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + } + + @Test + public void testGetMessageForPublishing() throws Exception { + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + // add two recoverable messages + final int recoverableMessageSizeAfterFirstInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 2 after first insert", + recoverableMessageSizeAfterFirstInsert == 2); + // add two more recoverable messages + final int recoverableMessageSizeAfterSecondInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 4 after second insert", + recoverableMessageSizeAfterSecondInsert == 4); + // Now get all messages which must drain out batch queue + final List messagesToPublish = publisherQueue.getMessageForPublishing(); + assertTrue("There must be 6 messages to publish", messagesToPublish.size() == 6); + // add two more batch and recovery messages + final int batchQueueSize = publisherQueue.addBatchMessages(getTwoSampleMessages()); + final int recoveryQueueSize = publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + final int messagePublishCount = publisherQueue.getMessageForPublishing().size(); + assertTrue("Batch Queue + Recovery Queue message total must batch publish message count", + messagePublishCount == (batchQueueSize + recoveryQueueSize)); + assertTrue("Batch Queue must be empty", publisherQueue.getBatchQueueRemainingSize() == 10); + assertTrue("Recovery Queue must be empty", publisherQueue.getRecoveryQueueRemainingSize() == 20); + + } + + @Test + public void testGetBatchQueueRemainingSize() throws Exception { + + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + assertTrue("Batch remaining capacity should be reduced by 2", + publisherQueue.getBatchQueueRemainingSize() == 8); + + // add two recoverable messages + final int recoverableMessageSizeAfterFirstInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 2 after first insert", + recoverableMessageSizeAfterFirstInsert == 2); + + // recoverable message should not change batch queue capacity + assertTrue("Adding recoverable Message must not have any impact on batch queue remaining capacity ", + publisherQueue.getBatchQueueRemainingSize() == 8); + // Now get all messages which must drain out batch queue + final List messagesToPublish = publisherQueue.getMessageForPublishing(); + assertTrue("There must be exactly 4 messages to publish", messagesToPublish.size() == 4); + + // Batch queue remaining capacity should now match original batch size + assertTrue("Batch Queue remaining capacity must match original batch queue size", publisherQueue + .getBatchQueueRemainingSize() == 10); + } + + @Test + public void testGetRecoveryQueueRemainingSize() throws Exception { + DMaaPMRPublisherQueue publisherQueue = new DMaaPMRPublisherQueueImpl(10, 20); + + // add two recoverable messages + final int recoverableMessageSizeAfterFirstInsert = + publisherQueue.addRecoverableMessages(getTwoSampleMessages()); + assertTrue("Recovery Message Queue size must be 2 after first insert", + recoverableMessageSizeAfterFirstInsert == 2); + assertTrue("Recovery Queue remaining capacity should be reduced by 2", + publisherQueue.getRecoveryQueueRemainingSize() == 18); + + // add two messages to batch queue + final int batchMessagesSizeAfterFirstInsert = publisherQueue.addBatchMessages(getTwoSampleMessages()); + assertTrue("Batch Message Queue size must be 2", batchMessagesSizeAfterFirstInsert == 2); + + // batch message should not change recoverable queue capacity + assertTrue("Adding batch queue Message must not have any impact on recovery queue remaining capacity ", + publisherQueue.getRecoveryQueueRemainingSize() == 18); + + // Now get all messages which must drain out recovery queue + final List messagesToPublish = publisherQueue.getMessageForPublishing(); + assertTrue("There must be exactly 4 messages to publish", messagesToPublish.size() == 4); + + // Recoverable queue remaining capacity should now match original recovery queue size + assertTrue("Recoverable Queue remaining capacity must match original batch queue size", publisherQueue + .getRecoveryQueueRemainingSize() == 20); + } + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java new file mode 100644 index 0000000..84fea09 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/publisher/DMaaPMRPublisherQueueMockImpl.java @@ -0,0 +1,53 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.publisher; + +import java.util.List; + +/** + * @author Manjesh Gowda. Creation Date: 11/7/2016. + */ +public class DMaaPMRPublisherQueueMockImpl implements DMaaPMRPublisherQueue { + @Override + public int addBatchMessages(List batchMessages) throws IllegalStateException { + return 100; + } + + @Override + public int addRecoverableMessages(List recoverableMessages) throws IllegalStateException { + return 0; + } + + @Override + public List getMessageForPublishing() { + return null; + } + + @Override + public int getBatchQueueRemainingSize() { + return 0; + } + + @Override + public int getRecoveryQueueRemainingSize() { + return 0; + } +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java new file mode 100644 index 0000000..f206aa2 --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberImplTest.java @@ -0,0 +1,158 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.subscriber; + +import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.BaseAnalyticsDMaaPUnitTest; +import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; + +import java.io.IOException; +import java.util.Random; +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.isA; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.BDDMockito.given; + +/** + * @author Rajiv Singla. Creation Date: 10/21/2016. + */ +@RunWith(MockitoJUnitRunner.class) +public class DMaaPMRSubscriberImplTest extends BaseAnalyticsDMaaPUnitTest { + + @Mock + CloseableHttpClient closeableHttpClient; + + private String consumerGroup, consumerId; + + @Before + public void setUp() throws Exception { + Random random = new Random(10000L); + consumerGroup = "Test-Consumer-Group" + Long.toString(random.nextLong()); + consumerId = UUID.randomUUID().toString(); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testSubscriberSuccessfullyReceiveDmaapMessage() throws Exception { + + String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," + + "{\"message\":\"I'm Object 2 Message\"}]"; + Mockito.when( + closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, testMessages)); + + DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( + getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); + assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); + assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2)); + } + + @Test + public void testSubscriberSuccessfullyReceiveDmaapMessageWithNoUsername() throws Exception { + + DMaaPMRSubscriberConfig dmaapMRSubscriberConfig = new DMaaPMRSubscriberConfig.Builder(HOST_NAME, TOPIC_NAME) + .setPortNumber(PORT_NUMBER) + .setProtocol(HTTP_PROTOCOL) + .setContentType(CONTENT_TYPE) + .setConsumerGroup(consumerGroup != null ? consumerGroup : SUBSCRIBER_CONSUMER_GROUP_NAME) + .setConsumerId(consumerId != null ? consumerId : SUBSCRIBER_CONSUMER_ID) + .setTimeoutMS(SUBSCRIBER_TIMEOUT_MS) + .setMessageLimit(SUBSCRIBER_MESSAGE_LIMIT).build(); + + String testMessages = "[{\"message\":\"I'm Object 1 Message\"}," + + "{\"message\":\"I'm Object 2 Message\"}]"; + Mockito.when( + closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, testMessages)); + + DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( + dmaapMRSubscriberConfig, closeableHttpClient); + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); + assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); + assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(2)); + } + + @Test + public void testSubscriberSuccessfullyReceiveNoDmaapMessage() throws Exception { + Mockito.when( + closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(200, null)); + + DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( + getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); + assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(200)); + assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0)); + } + + @Test + public void testSubscriberSuccessfullyReceiveErrorMessage() throws Exception { + Mockito.when( + closeableHttpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))) + .thenReturn(new ImmutablePair<>(400, "Bad Request")); + + DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( + getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); + assertThat(dmaapMRSubscriberResponse.getResponseCode(), is(400)); + assertThat(dmaapMRSubscriberResponse.getFetchedMessages(), IsCollectionWithSize.hasSize(0)); + } + + @Rule + public ExpectedException httpIOException = ExpectedException.none(); + + @Test + public void testSubscriberSuccessfullyReceiveException() throws Exception { + + httpIOException.expect(DCAEAnalyticsRuntimeException.class); + httpIOException.expectCause(isA(IOException.class)); + + given(closeableHttpClient.execute( + Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).willThrow(IOException.class); + + DMaaPMRSubscriberImpl dmaapMRSubscriberImpl = new DMaaPMRSubscriberImpl( + getSubscriberConfig(consumerId, consumerGroup), closeableHttpClient); + DMaaPMRSubscriberResponse dmaapMRSubscriberResponse = dmaapMRSubscriberImpl.fetchMessages(); + } + +} diff --git a/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java new file mode 100644 index 0000000..92a795a --- /dev/null +++ b/dcae-analytics-dmaap/src/test/java/org/openecomp/dcae/apod/analytics/dmaap/service/subscriber/DMaaPMRSubscriberMockImpl.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START========================================================= + * dcae-analytics + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.dcae.apod.analytics.dmaap.service.subscriber; + +import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponseImpl; + +import java.util.Date; + +/** + * @author Rajiv Singla. Creation Date: 10/21/2016. + */ +public class DMaaPMRSubscriberMockImpl implements DMaaPMRSubscriber { + + @Override + public DMaaPMRSubscriberResponse fetchMessages() throws DCAEAnalyticsRuntimeException { + return new DMaaPMRSubscriberResponseImpl(102, "Mock Response", null); + } + + @Override + public Date getSubscriberCreationTime() { + return null; + } + + @Override + public void close() throws Exception { + + } +} diff --git a/dcae-analytics-model/pom.xml b/dcae-analytics-model/pom.xml index 58e1da8..5633267 100644 --- a/dcae-analytics-model/pom.xml +++ b/dcae-analytics-model/pom.xml @@ -28,7 +28,7 @@ 4.0.0 - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics 1.0-SNAPSHOT ../pom.xml @@ -104,7 +104,7 @@ - org.openecomp.dcae.analytics + org.openecomp.dcae.apod.analytics dcae-analytics-test 1.0-SNAPSHOT test diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/BaseDynamicPropertiesProvider.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/BaseDynamicPropertiesProvider.java deleted file mode 100644 index 59c2a46..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/BaseDynamicPropertiesProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain; - -import lombok.Data; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - *

- * Base Dynamic Provider provide functionality so that all the - * additional dynamic Properties can be accumalated in a map. - *

- * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -@Data -public abstract class BaseDynamicPropertiesProvider implements DynamicPropertiesProvider { - - /** - * All non-required properties should be captured in additional properties - * - * @param dynamicProperties Dynamic properties - * @return dynamic properties - */ - private Map dynamicProperties = new LinkedHashMap<>(); - - - /** - * Add a dynamic property to Common Event Format Entity - * - * @param propertyName property name - * @param propertyValue property value - */ - public void addDynamicProperties(String propertyName, Object propertyValue) { - dynamicProperties.put(propertyName, propertyValue); - } - - /** - * Determines if dynamic properties are present for the CEF Entity - * - * @return return true if Dynamic Properties are present - */ - public boolean isDynamicPropertiesPresent() { - return dynamicProperties.size() == 0; - } - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DCAEAnalyticsModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DCAEAnalyticsModel.java deleted file mode 100644 index 79650b5..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DCAEAnalyticsModel.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain; - -import java.io.Serializable; - -/** - *

- * Marker Interface for all DCAE Analytics Model implementations - *

- * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -public interface DCAEAnalyticsModel extends Serializable { -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DynamicPropertiesProvider.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DynamicPropertiesProvider.java deleted file mode 100644 index 55eef6b..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/DynamicPropertiesProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain; - -import java.util.Map; - -/** - *

- * Problem: Many Entities have dynamic properties as well as known properties. - * Known properites can be binded explicitly with all dynamic properties need - * to be captured also ensuring that there must not be any loss in information - * during deserialization / serialization process. - *

- *

- * This contract allows the deserialization mechanism to catch those dynamic properties - * in a Map so that deserialization mechanism will not loose any information and - * can be serialized back with no loss in dynamic properties information - *

- * @author Rajiv Singla. Creation Date: 10/18/2016. - */ -public interface DynamicPropertiesProvider extends DCAEAnalyticsModel { - - - void addDynamicProperties(String propertyName, Object propertyValue); - - Map getDynamicProperties(); -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertAction.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertAction.java deleted file mode 100644 index a0e68f3..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertAction.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -/** - * Common Event Format Alert Action - * - * @author Rajiv Singla. Creation Date: 11/3/2016. - */ -public enum AlertAction implements CEFModel { - - CLEAR, CONT, SET; - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertType.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertType.java deleted file mode 100644 index 2dcce07..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/AlertType.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -/** - * - * @author Rajiv Singla. Creation Date: 11/3/2016. - */ -public enum AlertType implements CEFModel { - - CARD_ANOMALY("CARD-ANOMALY"), - ELEMENT_ANOMALY("ELEMENT-ANOMALY"), - INTERFACE_ANOMALY("INTERFACE-ANOMALY"), - SERVICE_ANOMALY("SERVICE-ANOMALY"), - UNKNOWN(null); - - private String name; - - AlertType(String name) { - this.name = name; - } - - public String getName() { - return name; - } - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/BaseCEFModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/BaseCEFModel.java deleted file mode 100644 index dbf4e83..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/BaseCEFModel.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.openecomp.dcae.analytics.model.domain.BaseDynamicPropertiesProvider; - -/** - *

- * Base CEF Model should be extended by all CEF Model Entities. - * By extending CEF Model all the additional dynamic Properties - * can be accumalated in a map. - *

- * - * @author Rajiv Singla. Creation Date: 10/18/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public abstract class BaseCEFModel extends BaseDynamicPropertiesProvider implements CEFModel { - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CEFModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CEFModel.java deleted file mode 100644 index b7f1328..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CEFModel.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import org.openecomp.dcae.analytics.model.domain.DCAEAnalyticsModel; - -/** - *

- * Marker interface for all DCAE Analytics Common Event Format Model implementations - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -public interface CEFModel extends DCAEAnalyticsModel { - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CommonEventHeader.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CommonEventHeader.java deleted file mode 100644 index 427e947..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/CommonEventHeader.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * Fields common to all Events - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class CommonEventHeader extends BaseCEFModel { - - - private static final long serialVersionUID = -7114956462480792282L; - - /** - * The eventing domain associated with this event - * - * @param domain New value for domain - * @return The eventing domain associated with this event - */ - private String domain; - - /** - * Event key that is unique to the event source - * - * @param eventId New value for event key - * @return Event key that is unique to the event source - */ - private String eventId; - - /** - * Function of the source e.g. eNodeB, MME, PCRF - * - * @param functionalRole New value for functional Role - * @return Function of the source e.g. eNodeB, MME, PCRF - */ - private String functionalRole; - - - /** - * The latest unix time aka epoch time associated with the event from any component--as microseconds elapsed since - * 1 Jan 1970 not including leap seconds - * - * @param lastEpochMicrosec New value for last Epoc Microsec - * @return The latest unix time associated with the event from any component - */ - private Long lastEpochMicrosec; - - - /** - * Processing Priority - * - * @param priority New value for processing Priority - * @return Processing Priority - */ - private Priority priority; - - - /** - * Name of the entity reporting the event, for example, an OAM VM - * - * @param reportingEntityName New value for reporting Entity Name - * @return Name of the entity reporting the event, for example, an OAM VM - */ - private String reportingEntityName; - - - /** - * Ordering of events communicated by an event source instance or 0 if not needed - * - * @param sequence New value for Sequence - * @return Ordering of events communicated by an event source instance or 0 if not needed - */ - private Integer sequence; - - - /** - * Name of the entity experiencing the event issue - * - * @param sourceName New value for source name - * @return Name of the entity experiencing the event issue - */ - private String sourceName; - - - /** - * the earliest unix time aka epoch time associated with the event from any component--as microseconds elapsed - * since 1 Jan 1970 not including leap seconds - * - * @param startEpochMicrosec New value for start Epoc Microsec - * @return The earliest unix time associated with the event from any component - */ - private Long startEpochMicrosec; -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Criticality.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Criticality.java deleted file mode 100644 index 51b7bee..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Criticality.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -/** - * Performance Criticality - * - * @author Rajiv Singla. Creation Date: 11/3/2016. - */ -public enum Criticality implements CEFModel { - - CRIT, MAJ; -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Event.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Event.java deleted file mode 100644 index 9c5ff2e..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Event.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * Generic Event Format - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class Event extends BaseCEFModel { - - - private static final long serialVersionUID = 136409326067482936L; - - /** - * Fields common to all Events - * - * @param commonEventHeader New value for common Event Header - * @return Fields common to all Events - */ - private CommonEventHeader commonEventHeader; - - /** - * MeasurementsForVfScaling fields - * - * @param measurementsForVfScalingFields New value for MeasurementsForVfScaling - * @return MeasurementsForVfScaling fields - */ - private MeasurementsForVfScalingFields measurementsForVfScalingFields; - - /** - * Threshold crossing Fields - * - * @param thresholdCrossingAlertFields New value for Threshold crossing Fields - * @return Threshold crossing Fields - */ - private ThresholdCrossingAlertFields thresholdCrossingAlertFields; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventListener.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventListener.java deleted file mode 100644 index ec9e64b..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * Common Event Format - Base Event Listener - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class EventListener extends BaseCEFModel { - - - private static final long serialVersionUID = -2173233681841558721L; - /** - * Common Event Format - Event - * - * @param event New value for Event - * @return Common Event Format Event - */ - private Event event; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventSeverity.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventSeverity.java deleted file mode 100644 index 178c49f..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/EventSeverity.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -/** - * CEF Event severity or priority - * - * @author Rajiv Singla. Creation Date: 11/3/2016. - */ -public enum EventSeverity implements CEFModel { - - //NOTE: enum order must not be changed. Events severity is ordered from high to low - CRITICAL, - MAJOR, - MINOR, - WARNING, - NORMAL; -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/MeasurementsForVfScalingFields.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/MeasurementsForVfScalingFields.java deleted file mode 100644 index d859f97..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/MeasurementsForVfScalingFields.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -/** - * Common Event Format - MeasurementsForVfScaling fields - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class MeasurementsForVfScalingFields extends BaseCEFModel { - - - private static final long serialVersionUID = 243977479034730554L; - - /** - * Interval over which measurements are being reported in seconds - * - * @param measurementInterval New value for measurement Interval - * @return Interval over which measurements are being reported in seconds - */ - private Long measurementInterval; - - /** - * Virtual Network Card Usage Array - * - * @param vNicUsageArray New value for Virtual Network Card Usage Array - * @return Virtual Network Card Usage Array - */ - private List vNicUsageArray; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/PerformanceCounter.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/PerformanceCounter.java deleted file mode 100644 index 1c8367a..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/PerformanceCounter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * Common Event Format - Performance PerformanceCounter - * - * @author Rajiv Singla. Creation Date: 11/3/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class PerformanceCounter extends BaseCEFModel { - - private static final long serialVersionUID = -8170148763083554044L; - /** - * Performance Counter Criticality - * - * @param criticality New value for Criticality - * @return Performance Counter Criticality - */ - private Criticality criticality; - /** - * Performance Counter Name - * - * @param name New value for Performance counter name - * @return Performance Counter Name - */ - private String name; - /** - * Performance Counter Threshold Crossed - * - * @param thresholdCrossed New value for Performance Counter Threshold Crossed - * @return Performance Counter Threshold Crossed - */ - private String thresholdCrossed; - /** - * Performance Counter Value - * - * @param value New Performance Counter Value - * @return Performance Counter Value - */ - private String value; - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Priority.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Priority.java deleted file mode 100644 index d6d1a7b..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/Priority.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -/** - * Common Event Format - Event processing priority - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -public enum Priority implements CEFModel { - - High, Medium, Normal, Low; - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/ThresholdCrossingAlertFields.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/ThresholdCrossingAlertFields.java deleted file mode 100644 index 575d5c6..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/ThresholdCrossingAlertFields.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -/** - * Common Event Format - Fields Specific to threshold crossing alert events - * - * @author Rajiv Singla. Creation Date: 11/3/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class ThresholdCrossingAlertFields extends BaseCEFModel { - - private static final long serialVersionUID = 1847494357841191942L; - - /** - * Additional Performance counters - * - * @param additionalParameters New value for Additional Performance counters - * @return Additional Performance counters - */ - private List additionalParameters; - - /** - * Event Action - * - * @param alertAction New Event Action - * @return Event Action - */ - private AlertAction alertAction; - - /** - * Unique short alert description such as IF-SHUB-ERRDROP - * - * @param alertDescription New value for Unique short alert description - * @return Unique short alert description - */ - private String alertDescription; - - /** - * Alert type - * - * @param alertType New value for Alert Type - * @return Alert Type - */ - private AlertType alertType; - - /** - * Calculated API value (if applicable) - * - * @param alertValue New Calculated API value - * @return Calculated API value (if applicable) - */ - private String alertValue; - - /** - * List of eventIds associated with the event being reported - * - * @param associatedAlertIdList New value for eventIds associated with the event - * @return List of eventIds associated with the event being reported - */ - private List associatedAlertIdList; - - /** - * Time when the performance collector picked up the data; with RFC 2822 compliant format: - * ‘Sat, 13 Mar 2010 11:29:05 -0800’ - * - * @param collectionTimestamp Set new value for time when the performance collector picked up the data - * @return Time when the performance collector picked up the data - */ - private String collectionTimestamp; - - /** - * Specific performance collector instance used - * - * @param dataCollector New value for specific performance collector instance used - * @return Specific performance collector instance used - */ - private String dataCollector; - - /** - * Type of network element - * - * @param elementType New value for type of network element - * @return Type of network element - */ - private String elementType; - - /** - * Event severity or priority - * - * @param eventSeverity New value for event severity or priority - * @return Event severity or priority - */ - private EventSeverity eventSeverity; - - /** - * Time closest to when the measurement was made; with RFC 2822 compliant format: ‘Sat, 13 Mar 2010 11:29:05 -0800’ - * - * @param eventStartTimestamp New value for time closest to when the measurement was made - * @return Time closest to when the measurement was made - */ - private String eventStartTimestamp; - - /** - * Physical or logical port or card (if applicable) - * - * @param interfaceName New value for Physical or logical port or card (if applicable) - * @return Physical or logical port or card (if applicable) - */ - private String interfaceName; - - /** - * Network name - * - * @param networkService New value for network name - * @return Network name - */ - private String networkService; - - /** - * Possible Root Cause (reserved for future use) - * - * @param possibleRootCause New value for possible root cause (reserved for future) - * @return Possible Root Cause (reserved for future use) - */ - private String possibleRootCause; - - /** - * Version of the thresholdCrossingAlertFields block - * - * @param thresholdCrossingFieldsVersion New value for version of the thresholdCrossingAlertFields block - * @return Version of the thresholdCrossingAlertFields block - */ - private Integer thresholdCrossingFieldsVersion; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/VNicUsageArray.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/VNicUsageArray.java deleted file mode 100644 index c4630ba..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/cef/VNicUsageArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.cef; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * Usage of an array of virtual network interface cards - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class VNicUsageArray extends BaseCEFModel { - - - private static final long serialVersionUID = -5710133694409971093L; - - /** - * Virtual Network Card - Bytes In - * - * @param bytesIn New value for Virtual Network Card - Bytes In - * @return Virtual Network Card - Bytes In - */ - private Long bytesIn; - - /** - * Virtual Network Card - Bytes Out - * - * @param bytesOut New value for Virtual Network Card - Bytes Out - * @return Virtual Network Card - Bytes Out - */ - private Long bytesOut; - - /** - * Virtual Network Card - Packets In - * - * @param packetsIn New value for Virtual Network Card - Packets In - * @return Virtual Network Card - Packets In - */ - private Long packetsIn; - - /** - * Virtual Network Card - Packets Out - * - * @param packetsOut New value for Virtual Network Card - Packets Out - * @return Virtual Network Card - Packets Out - */ - private Long packetsOut; - - /** - * Virtual Network Card Identifier - * - * @param vNicIdentifier New value for Virtual Network Card Identifier - * @return Virtual Network Card Identifier - */ - private String vNicIdentifier; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/PolicyModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/PolicyModel.java deleted file mode 100644 index 1825390..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/PolicyModel.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy; - -import org.openecomp.dcae.analytics.model.domain.DCAEAnalyticsModel; - -/** - *

- * Marker Interface all DCAE Analytics Policy Model implementations - *

- * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -public interface PolicyModel extends DCAEAnalyticsModel { -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/BaseTCAPolicyModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/BaseTCAPolicyModel.java deleted file mode 100644 index b2a9d21..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/BaseTCAPolicyModel.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy.tca; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.openecomp.dcae.analytics.model.domain.BaseDynamicPropertiesProvider; - -/** - *

- * A Base TCA Policy Model which accumulates all dynamic properties in a dynamicProperties Map - *

- * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public abstract class BaseTCAPolicyModel extends BaseDynamicPropertiesProvider implements TCAPolicyModel { -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Direction.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Direction.java deleted file mode 100644 index 8d3a8b0..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Direction.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy.tca; - -import javax.annotation.Nonnull; - -/** - *

- * Enum for Threshold Direction - *

- * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -public enum Direction implements TCAPolicyModel { - - LESS { - public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) { - return value1 < value2; - } - }, - LESS_OR_EQUAL { - public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) { - return value1 <= value2; - } - }, - GREATER { - public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) { - return value1 > value2; - } - }, - GREATER_OR_EQUAL { - public Boolean operate(@Nonnull Long value1, @Nonnull Long value2) { - return value1 >= value2; - } - }; - - public abstract Boolean operate(@Nonnull Long value1, @Nonnull Long value2); - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/MetricsPerFunctionalRole.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/MetricsPerFunctionalRole.java deleted file mode 100644 index 4d35ed4..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/MetricsPerFunctionalRole.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy.tca; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -/** - * TCA Metrics that need to applied to each functional Role - * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class MetricsPerFunctionalRole extends BaseTCAPolicyModel{ - - - private static final long serialVersionUID = -8819830294328242262L; - - /** - * Functional Role to which TCA Policy needs to applied. - * - * @param functionalRole New value for Functional Role to which TCA Policy needs to applied - * @return Functional Role to which TCA Policy needs to applied - */ - private String functionalRole; - - /** - * Policy Scope - * - * @param policyScope New value for Policy Scope - * @return Policy Scope - */ - private String policyScope; - - /** - * Policy Name - * - * @param policyName New value for Policy Name - * @return Policy Name - */ - private String policyName; - - /** - * Policy Version - * - * @param policyVersion New value for Policy Version - * @return Policy Version - */ - private String policyVersion; - - /** - * Policy Thresholds - * - * @param thresholds New value for Policy Thresholds - * @return Policy Thresholds - */ - private List thresholds; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicy.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicy.java deleted file mode 100644 index 031ccb0..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicy.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy.tca; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.openecomp.dcae.analytics.model.domain.cef.CommonEventHeader; - -import java.util.List; - -/** - *

- * TCA (Threshold Crossing Alert) Root - *

- * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class TCAPolicy extends BaseTCAPolicyModel { - - private static final long serialVersionUID = 9186451218579196970L; - - /** - * TCA Policy domain which is associated with TCA incoming CEF message {@link CommonEventHeader#getDomain()} - * - * @param domain New value for domain - * @return Policy domain which is associated with incoming CEF message - */ - private String domain; - - /** - * Contains TCA Policy metrics that needs to be applied to each Functional Role - * - * @param metricsPerFunctionalRole New value for metrics that needs to be applied to each Functional Role - * @return Contains TCA Policy metrics that needs to be applied to each Functional Role - */ - private List metricsPerFunctionalRole; - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicyModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicyModel.java deleted file mode 100644 index ceec46d..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/TCAPolicyModel.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy.tca; - -import org.openecomp.dcae.analytics.model.domain.policy.PolicyModel; - -/** - *

- * Marker interface for all TCA Policy Models - *

- * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -public interface TCAPolicyModel extends PolicyModel { - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Threshold.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Threshold.java deleted file mode 100644 index 0905730..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/domain/policy/tca/Threshold.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.domain.policy.tca; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.openecomp.dcae.analytics.model.domain.cef.EventSeverity; - -/** - * - * @author Rajiv Singla. Creation Date: 11/5/2016. - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class Threshold extends BaseTCAPolicyModel { - - private static final long serialVersionUID = 5714225046339409812L; - - /** - * Closed Loop Control Name - * - * @param closedLoopControlName New value for Closed Loop Control Name - * @return Closed Loop Control Name - */ - private String closedLoopControlName; - - /** - * Threshold Version - * - * @param version New value for Threshold Version - * @return Threshold Version - */ - private String version; - - /** - * Path of the field inside Common Event Format which needs to be monitored by TCA App - * for threshold crossing - * - * @param fieldPath New value for Path of the field inside CEF which needs to be monitored for TCA - * @return Path of the field inside Common Event Format which needs to be monitored by TCA App - */ - private String fieldPath; - - /** - * Threshold Value - * - * @param thresholdValue New value for Threshold Value - * @return Threshold Value - */ - private Long thresholdValue; - - /** - * Direction of threshold - * - * @param direction New value for Direction of threshold - * @return Direction of threshold - */ - private Direction direction; - - /** - * Severity of Event based on CEF Convention - * - * @param severity New value for Severity of Event based on CEF Convention - * @return Severity of Event based on CEF Convention - */ - private EventSeverity severity; - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/FacadeModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/FacadeModel.java deleted file mode 100644 index abf6d36..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/FacadeModel.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.facade; - -import java.io.Serializable; - -/** - *

- * Marker Interface for all Facade (outgoing) DCAE Analytics Model - *

- * - * @author Rajiv Singla. Creation Date: 11/9/2016. - */ -public interface FacadeModel extends Serializable { -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/AAI.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/AAI.java deleted file mode 100644 index fa08f07..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/AAI.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.facade.tca; - -import lombok.Data; - -/** - * - * @author Rajiv Singla. Creation Date: 11/9/2016. - */ -@Data -public class AAI implements TCAFacadeModel { - - private static final long serialVersionUID = 1255011931120081985L; - - private String genericVNFId; - - private String genericServerId; - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAFacadeModel.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAFacadeModel.java deleted file mode 100644 index 78c4ae7..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAFacadeModel.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.facade.tca; - -import org.openecomp.dcae.analytics.model.facade.FacadeModel; - -/** - * Marker Interface for all TCA Facade Models - * - * @author Rajiv Singla. Creation Date: 11/9/2016. - */ -public interface TCAFacadeModel extends FacadeModel { -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAVESResponse.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAVESResponse.java deleted file mode 100644 index f5a5b4e..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/facade/tca/TCAVESResponse.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.facade.tca; - -import lombok.Data; - -/** - * Response generated by TCA for VES Message - * - * @author Rajiv Singla. Creation Date: 11/9/2016. - */ -@Data -public class TCAVESResponse implements TCAFacadeModel { - - private static final long serialVersionUID = 8505119543756702710L; - - private String closedLoopControlName; - private String version; - private String requestID; - private Long closedLoopAlarmStart; - private String closedLoopEventClient; - private String targetType; - private AAI aai; - private String target; - private String from; - private String policyScope; - private String policyName; - private String policyVersion; - private String closedLoopEventStatus; - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelIOUtils.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelIOUtils.java deleted file mode 100644 index 0eddd20..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelIOUtils.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.util.Properties; - -/** - * Utility class containing methods for IO related operations - *

- * @author Rajiv Singla. Creation Date: 10/17/2016. - */ -public abstract class AnalyticsModelIOUtils extends AnalyticsModelJsonUtils { - - private static final Logger LOG = LoggerFactory.getLogger(AnalyticsModelIOUtils.class); - - /** - * Parses given valid JSON file Location to object of given binding class type. - * - * @param fileLocation - Valid JSON File Location - * @param bindingClass - Class Type of Binding object - * @param - Binding Class Type - * @return - Binding Class Object which properties populated from JSON File Location - */ - public static final T convertToJsonObject(String fileLocation, Class bindingClass) { - - // Load Resource from give path - final InputStream resourceAsStream = loadResourceAsStream(fileLocation); - - // If resource is null throw an exception - if (resourceAsStream == null) { - final String errorMessage = String.format("Invalid File location: %s", fileLocation); - logAndThrowFileNotFoundException(errorMessage); - } - - // Parse input stream - try (InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, Charset.forName("UTF-8"))) { - - return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(inputStreamReader, bindingClass); - - } catch (IOException e) { - - // If parsing fails due to IO Issues throw an exception - final String errorMessage = String.format("IO Error while parsing Json File location: %s", fileLocation); - LOG.error(errorMessage); - throw new RuntimeException(errorMessage, e); - - } catch (Exception e) { - - //If parsing fails due to Invalid Json or Json IO Issues throw an exception - final String errorMessage = String.format("Json parsing error while parsing Json File location: %s", - fileLocation); - LOG.error(errorMessage); - throw new RuntimeException(errorMessage, e); - - } - - } - - public static Properties loadPropertiesFile(String propertiesFileLocation) { - - // Load Resource from give properties file path - final InputStream propertiesFileInputStream = loadResourceAsStream(propertiesFileLocation); - - // If properties file is not present throw an exception - if (propertiesFileInputStream == null) { - final String errorMessage = String.format("Invalid Properties File at location: %s", - propertiesFileLocation); - logAndThrowFileNotFoundException(errorMessage); - } - - final Properties properties = new Properties(); - - try { - properties.load(propertiesFileInputStream); - } catch (IOException e) { - final String errorMessage = String.format("IO Exception while reading Properties File at location: %s", - propertiesFileLocation); - logAndThrowRuntimeException(errorMessage, e); - } - - return properties; - - } - - /** - * Loads Input file from the given classpath file location and returns file InputStream - * - * @param fileLocation - classpath file location - * @return - {@link InputStream} for classpath file - */ - public static InputStream loadResourceAsStream(String fileLocation) { - // Load Resource from give path - return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileLocation); - } - - - /** - * Throws a new Runtime exception for new {@link FileNotFoundException} and logs it as an error - * - * @param errorMessage - */ - private static void logAndThrowFileNotFoundException(String errorMessage) { - logAndThrowRuntimeException(errorMessage, new FileNotFoundException(errorMessage)); - } - - /** - * Wraps checked exception into a runtime exception and log it as an error - * - * @param errorMessage - * @param actualException - */ - private static void logAndThrowRuntimeException(String errorMessage, Exception actualException) { - - LOG.error(errorMessage); - throw new RuntimeException(errorMessage, actualException); - - } - - -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelJsonUtils.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelJsonUtils.java deleted file mode 100644 index 9e6b719..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/AnalyticsModelJsonUtils.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.util; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Suppliers; -import org.openecomp.dcae.analytics.model.util.json.AnalyticsModelObjectMapperSupplier; - -import java.io.IOException; -import java.io.InputStream; - -/** - * - * @author Rajiv Singla. Creation Date: 11/7/2016. - */ -public abstract class AnalyticsModelJsonUtils { - - /** - * Object mapper to be used for all TCA Json Parsing - */ - protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER = - Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get(); - - - /** - * Converts Input Stream to given type reference object - * - * @param inputStream input stream - * @param valueTypeRef type reference - * @param type of type reference - * - * @return parsed json object - * - * @throws IOException IO Exception - */ - public static T readValue(InputStream inputStream, TypeReference valueTypeRef) throws IOException { - return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(inputStream, valueTypeRef); - } - - - /** - * Converts Input Stream to given target class object - * - * @param inputStream input stream - * @param targetClass target class type - * @param type of class - * - * @return parsed json object - * - * @throws IOException IO Exception - */ - public static T readValue(InputStream inputStream, Class targetClass) throws IOException { - return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(inputStream, targetClass); - } - - - /** - * Converts given object to JSON string - * - * @param value object that needs to converted to json string - * - * @return json string - * @throws JsonProcessingException Json Processing exception - */ - public static String writeValueAsString(Object value) throws JsonProcessingException { - return ANALYTICS_MODEL_OBJECT_MAPPER.writeValueAsString(value); - } - - - /** - * Method to deserialize JSON content from given JSON content String. - * - * @param jsonString JSON String - * @param objectClass target object class - * @param object class type - * - * @return converted Object from JSON String - * - * @throws IOException IO Exception - */ - public static T readValue(final String jsonString, final Class objectClass) throws IOException { - return ANALYTICS_MODEL_OBJECT_MAPPER.readValue(jsonString, objectClass); - } -} diff --git a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/AnalyticsModelObjectMapperSupplier.java b/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/AnalyticsModelObjectMapperSupplier.java deleted file mode 100644 index 63857fc..0000000 --- a/dcae-analytics-model/src/main/java/org/openecomp/dcae/analytics/model/util/json/AnalyticsModelObjectMapperSupplier.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright © 2017 AT&T Intellectual Property. 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. - */ - -package org.openecomp.dcae.analytics.model.util.json; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Supplier; -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.JsonPath; -import com.jayway.jsonpath.Option; -import com.jayway.jsonpath.spi.json.JacksonJsonProvider; -import com.jayway.jsonpath.spi.json.JsonProvider; -import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; -import com.jayway.jsonpath.spi.mapper.MappingProvider; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -import java.util.EnumSet; -import java.util.Set; - -/** - *

- * {@link Supplier} that can be used by clients to get Object Mapper which specializes - * in serialize and deserialize - DCAE Analytics Model JSON Objects. Clients can - * choose to memoize this Supplier for performance enhancements - *
- * NOTE: This supplier also setups up {@link JsonPath} default - * config to make use of this Supplier object mapper - *

- * @author Rajiv Singla. Creation Date: 11/10/2016. - */ -@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") -public class AnalyticsModelObjectMapperSupplier implements Supplier { - - @Override - public ObjectMapper get() { - - final ObjectMapper objectMapper = new ObjectMapper(); - - // Don't Serialize null values - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - - // Don't fail on unknown properties - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - // Register Common Event Format Module - objectMapper.registerModule(new CommonEventFormatModule()); - // Register TCA Policy Module - objectMapper.registerModule(new TCAPolicyModule()); - // Register TCA Facade Module - objectMapper.registerModule(new TCAFacadeModelModule()); - - - // Setup JsonPath default config - setupJsonPathDefaultConfig(objectMapper); - - return objectMapper; - } - - - /** - * Setups up default Config for {@link JsonPath} - * - * @param objectMapper - */ - private void setupJsonPathDefaultConfig(final ObjectMapper objectMapper) { - - Configuration.setDefaults(new Configuration.Defaults() { - - private final JsonProvider jsonProvider = new JacksonJsonProvider(objectMapper); - private final MappingProvider mappingProvider = new JacksonMappingProvider(objectMapper); - - @Override - public JsonProvider jsonProvider() { - return jsonProvider; - } - - @Override - public MappingProvider mappingProvider() { - return mappingProvider; - } - - @Override - public Set