diff options
author | 2018-08-15 11:46:10 -0400 | |
---|---|---|
committer | 2018-08-16 11:09:15 -0400 | |
commit | 7a2c23b3ad83eab0eed5b990c70a1603447d5ee5 (patch) | |
tree | 24293333fd3cc566c1d77f9c9eedeb034dce9c6c /dcae-analytics/dcae-analytics-model/src | |
parent | 9650bd18f6b88721628ebedac2575b44e1b0028e (diff) |
Standalone TCA with EELF Logger
Issue-ID: DCAEGEN2-633
Change-Id: I4da76b532021c0d6248455e7bd6e77f4614c35a7
Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com>
Diffstat (limited to 'dcae-analytics/dcae-analytics-model/src')
74 files changed, 4020 insertions, 0 deletions
diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsHttpConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsHttpConstants.java new file mode 100644 index 0000000..421e158 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsHttpConstants.java @@ -0,0 +1,45 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +/** + * Captures various standard Analytics HTTP Request Headers + * + * @author Rajiv Singla + */ +public abstract class AnalyticsHttpConstants { + + public static final String REQUEST_ID_HEADER_KEY = "X-ECOMP-RequestID"; + public static final String REQUEST_TRANSACTION_ID_HEADER_KEY = "X-ECOMP-TransactionID"; + public static final String REQUEST_APP_NAME_HEADER_KEY = "X-ECOMP-FromAppID"; + public static final String REQUEST_BEGIN_TS_HEADER_KEY = "X-Begin-Timestamp"; + public static final String REQUEST_END_TS_HEADER_KEY = "X-End-Timestamp"; + + public static final String REQUEST_APP_NAME_HEADER_DEFAULT_VALUE = "DCAE-Analytics"; + + // DEFAULT HTTP CLIENT ID + public static final String DEFAULT_HTTP_CLIENT_ID_PREFIX = "DCAE-Analytics-Client-"; + + public static final String HTTP_STATUS_CODE_HEADER_KEY = "http_statusCode"; + + private AnalyticsHttpConstants() { + // private constructor + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java new file mode 100644 index 0000000..bb13ed6 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +import java.io.Serializable; + +/** + * Marker Interface for all DCAE Analytics Model implementations + * + * @author Rajiv Singla + */ +public interface AnalyticsModel extends Serializable { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModelConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModelConstants.java new file mode 100644 index 0000000..30fb5f7 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModelConstants.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +/** + * Contains constants for DCAE Analytics Model Module + * + * @author Rajiv Singla + */ +public abstract class AnalyticsModelConstants { + + public static final String JSON_MODULE_GROUP_ID = "org.onap.dcae.analytics.model"; + public static final String JSON_MODULE_ARTIFACT_ID = "dcae-analytics-model"; + + // ========================= UTILITIES =======================================// + // DATE CONSTANTS + public static final String ANALYTICS_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + // RANDOM ID + public static final Integer DEFAULT_RANDOM_ID_LENGTH = 5; + // UTF-8 CHARSET NAME + public static final String UTF8_CHARSET_NAME = "UTF-8"; + // REQUEST ID DELIMITER + public static final String ANALYTICS_REQUEST_ID_DELIMITER = ":"; + + private AnalyticsModelConstants() { + // private constructor + } + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsProfile.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsProfile.java new file mode 100644 index 0000000..c7f2872 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsProfile.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +/** + * Analytics Profiles + * + * @author Rajiv Singla + */ +public abstract class AnalyticsProfile { + + public static final String NEGATION_PREFIX = "!"; + + public static final String DEV_PROFILE_NAME = "dev"; + public static final String NOT_DEV_PROFILE_NAME = NEGATION_PREFIX + DEV_PROFILE_NAME; + public static final String CONFIG_BINDING_SERVICE_PROFILE_NAME = "configBindingService"; + public static final String NOT_CONFIG_BINDING_SERVICE_PROFILE_NAME = + NEGATION_PREFIX + CONFIG_BINDING_SERVICE_PROFILE_NAME; + public static final String DMAAP_PROFILE_NAME = "dmaap"; + public static final String NOT_DMAAP_PROFILE_NAME = NEGATION_PREFIX + DMAAP_PROFILE_NAME; + public static final String REDIS_PROFILE_NAME = "redis"; + public static final String NOT_REDIS_PROFILE_NAME = NEGATION_PREFIX + REDIS_PROFILE_NAME; + public static final String MONGO_PROFILE_NAME = "mongo"; + public static final String NOT_MONGO_PROFILE_NAME = NEGATION_PREFIX + MONGO_PROFILE_NAME; + + private AnalyticsProfile() { + // private constructor + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java new file mode 100644 index 0000000..1171f44 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/DmaapMrConstants.java @@ -0,0 +1,70 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @author Rajiv Singla + */ +public abstract class DmaapMrConstants { + + // ================== DMaaP MR CONSTANTS ============================== // + + public static final Set<String> DMAAP_MAPPED_HEADERS = Stream.of( + AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY, + AnalyticsHttpConstants.REQUEST_TRANSACTION_ID_HEADER_KEY, + AnalyticsHttpConstants.REQUEST_BEGIN_TS_HEADER_KEY, + AnalyticsHttpConstants.REQUEST_END_TS_HEADER_KEY).collect(Collectors.toSet()); + + + // MR SUBSCRIBER + public static final String SUBSCRIBER_EMPTY_MESSAGE_RESPONSE_STRING = "[]"; + public static final String SUBSCRIBER_RANDOM_CONSUMER_GROUP_PREFIX = "DCAE-SUB-"; + public static final String SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME = "timeout"; + public static final Integer SUBSCRIBER_DEFAULT_TIMEOUT = -1; + public static final Integer SUBSCRIBER_DEFAULT_FIXED_POLLING_INTERVAL = 30_000; + public static final String SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME = "limit"; + public static final Integer SUBSCRIBER_DEFAULT_MESSAGE_LIMIT = 50_000; + public static final Integer SUBSCRIBER_DEFAULT_PROCESSING_BATCH_SIZE = 10_000; + + + // =================== INTEGRATION DEFAULTS =========================== // + + // RETRY ON FAILURE + public static final Integer DEFAULT_NUM_OF_RETRIES_ON_FAILURE = 5; + public static final Integer DEFAULT_RETRY_INITIAL_INTERVAL = 1_000; + public static final Integer DEFAULT_RETRY_MULTIPLIER = 5; + public static final Integer DEFAULT_RETRY_MAX_INTERVAL = 300_000; + + public static final String DMAAP_MR_SUBSCRIBER_OUTPUT_CHANNEL_NAME = "mrSubscriberOutputChannel"; + public static final String DMAAP_MR_PUBLISHER_INPUT_CHANNEL = "mrPublisherInputChannel"; + public static final String DMAAP_MR_PUBLISHER_OUTPUT_CHANNEL = "mrPublisherOutputChannel"; + + // MESSAGE STORE NAMES + public static final String DMAAP_MR_SUBSCRIBER_OUTPUT_MESSAGE_STORE_GROUP_ID = "mrSubscriberMessageStoreGroup"; + public static final String DMAAP_MR_PUBLISHER_RECOVERY_MESSAGE_STORE_GROUP_ID = "mrPublisherRecoveryStoreGroup"; + + public DmaapMrConstants() { + // private constructor + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/TcaModelConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/TcaModelConstants.java new file mode 100644 index 0000000..dbe0846 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/TcaModelConstants.java @@ -0,0 +1,72 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants; + +/** + * @author Rajiv Singla + */ +public abstract class TcaModelConstants { + + // =================== TCA CONSTANTS =========================== // + + // TCA Alert - VNF Constants + public static final String TCA_ALERT_VNF_TARGET_TYPE = "VNF"; + public static final String AAI_VNF_KEY_PREFIX = "generic-vnf."; + public static final String TCA_ALERT_VNF_TARGET = AAI_VNF_KEY_PREFIX + "vnf-name"; + // TCA Alert - VM Constants + public static final String TCA_ALERT_VM_TARGET_TYPE = "VM"; + public static final String AAI_VSERVER_KEY_PREFIX = "vserver."; + public static final String TCA_ALERT_VM_TARGET = AAI_VSERVER_KEY_PREFIX + "vserver-name"; + // VNF & VM - Common Constants + public static final String TCA_VES_RESPONSE_FROM = "DCAE"; + public static final String TCA_SERVICE_NAME = + ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE != null ? + ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE : "DCAE-TCA"; + + + // ================= PERSISTENCE CONSTANTS ================== // + public static final String TCA_ROW_KEY_DELIMITER = ":"; + + + // ======================= DEFAULTS ====================== // + public static final boolean DEFAULT_AAI_ENRICHMENT_ENABLED = false; + public static final boolean DEFAULT_ABATEMENT_ENABLED = true; + public static final boolean DEFAULT_ECOMP_LOGGING_ENABLED = true; + public static final Integer DEFAULT_TCA_PROCESSING_BATCH_SIZE = 10_000; + + public static final boolean DEFAULT_TCA_AAI_IGNORE_SSL_VALIDATION = false; + public static final String DEFAULT_TCA_AAI_GENERIC_VNF_PATH = "aai/v11/network/generic-vnfs/generic-vnf"; + public static final String DEFAULT_TCA_AAI_NODE_QUERY_PATH = "aai/v11/search/nodes-query"; + + public static final int TCA_ABATEMENT_SIMPLE_REPOSITORY_MAX_ENTITY_COUNT = 100_000; + public static final int TCA_ABATEMENT_SIMPLE_REPOSITORY_REMOVE_ENTITY_COUNT = 1_000; + + + //====================== REST API ===================== // + public static final String TCA_REST_API_PREFIX = "/api/v1/tca/"; + public static final String TCA_POLICY_ENDPOINT = "policy"; + public static final String TCA_EXECUTION_ENDPOINT = "execute"; + public static final String TCA_POLICY_SOURCE_HEADER_KEY = "X-TCA-POLICY-SOURCE"; + public static final String TCA_POLICY_CREATION_HEADER_KEY = "X-TCA-POLICY-CREATION-TIME"; + public static final String TCA_POLICY_VERSION_HEADER_KEY = "X-TCA-POLICY-VERSION"; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/AlertAction.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/AlertAction.java new file mode 100644 index 0000000..65483f2 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/AlertAction.java @@ -0,0 +1,31 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +/** + * Common Event Format Alert Action + * + * @author Rajiv Singla + */ +public enum AlertAction implements CEFModel { + + CLEAR, CONT, SET + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/AlertType.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/AlertType.java new file mode 100644 index 0000000..9b34809 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/AlertType.java @@ -0,0 +1,44 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +/** + * CEF Alert Type + * + * @author Rajiv Singla + */ +public enum AlertType implements CEFModel { + + CARD_ANOMALY("CARD-ANOMALY"), + ELEMENT_ANOMALY("ELEMENT-ANOMALY"), + INTERFACE_ANOMALY("INTERFACE-ANOMALY"), + SERVICE_ANOMALY("SERVICE-ANOMALY"), + UNKNOWN(null); + + private final String name; + + AlertType(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/BaseCEFModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/BaseCEFModel.java new file mode 100644 index 0000000..da90fd0 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/BaseCEFModel.java @@ -0,0 +1,37 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import org.onap.dcae.analytics.model.common.BaseDynamicPropertiesProvider; + +/** + * Base CEF Model should be extended by all CEF Model Entities. + * By extending CEF Model all the additional dynamic Properties + * can be accumulated in a map. + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public abstract class BaseCEFModel extends BaseDynamicPropertiesProvider implements CEFModel { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/CEFModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/CEFModel.java new file mode 100644 index 0000000..8f894c7 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/CEFModel.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import org.onap.dcae.analytics.model.AnalyticsModel; + +/** + * Marker interface for all DCAE Analytics Common Event Format Model implementations + * + * @author Rajiv Singla + */ +public interface CEFModel extends AnalyticsModel { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/CommonEventHeader.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/CommonEventHeader.java new file mode 100644 index 0000000..3398b51 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/CommonEventHeader.java @@ -0,0 +1,132 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Fields common to all Events + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CommonEventHeader extends BaseCEFModel { + + + private static final long serialVersionUID = 1L; + + /** + * The eventing domain associated with this event + */ + private Domain domain; + + /** + * Event key that is unique to the event source + */ + private String eventId; + + /** + * Unique event name + */ + private String eventName; + + + /** + * Event type e.g. applicationVnf, guestOS, hostOS, platform + */ + private String eventType; + + + /** + * Enrichment fields for internal VES Event Listener service use only, not supplied by event sources + */ + private InternalHeaderFields internalHeaderFields; + + + /** + * 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 + */ + private Long lastEpochMicrosec; + + + /** + * Three character network function component type as aligned with vfc naming standards + */ + private String nfcNamingCode; + + + /** + * Four character network function type as aligned with vnf naming standards + */ + private String nfNamingCode; + + + /** + * Processing Priority + */ + private Priority priority; + + + /** + * UUID identifying the entity reporting the event, for example an OAM VM; must be populated by the + * enrichment process + */ + private String reportingEntityId; + + + /** + * Name of the entity reporting the event, for example, an EMS name; may be the same as sourceName + */ + private String reportingEntityName; + + + /** + * Ordering of events communicated by an event source instance or 0 if not needed + */ + private Integer sequence; + + + /** + * UUID identifying the entity experiencing the event issue; must be populated by the enrichment process + */ + private String sourceId; + + + /** + * 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 + */ + private Long startEpochMicrosec; + + + /** + * Version of the event header + */ + private Float version; +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Criticality.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Criticality.java new file mode 100644 index 0000000..d8f0875 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Criticality.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +/** + * Performance Criticality + * + * @author Rajiv Singla + */ +public enum Criticality implements CEFModel { + + CRIT, MAJ, UNKNOWN +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Domain.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Domain.java new file mode 100644 index 0000000..2be00dc --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Domain.java @@ -0,0 +1,40 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +/** + * Eventing domain associated with the event + * + * @author Rajiv Singla + */ +public enum Domain implements CEFModel { + + fault, + heartbeat, + measurementsForVfScaling, + mobileFlow, + other, + sipSignaling, + stateChange, + syslog, + thresholdCrossingAlert, + voiceQuality; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Event.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Event.java new file mode 100644 index 0000000..aee213c --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Event.java @@ -0,0 +1,51 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Generic Event Format + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class Event extends BaseCEFModel { + + + private static final long serialVersionUID = 1L; + + /** + * Fields common to all Events + */ + private CommonEventHeader commonEventHeader; + + /** + * Measurements for Vf scaling fields + */ + private MeasurementsForVfScalingFields measurementsForVfScalingFields; + + /** + * Threshold crossing alert Fields. + */ + private ThresholdCrossingAlertFields thresholdCrossingAlertFields; +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/EventListener.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/EventListener.java new file mode 100644 index 0000000..50bf3d1 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/EventListener.java @@ -0,0 +1,41 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Common Event Format - Base Event Listener + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class EventListener extends BaseCEFModel { + + + private static final long serialVersionUID = 1L; + + /** + * Common Event Format - Event + */ + private Event event; +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/EventSeverity.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/EventSeverity.java new file mode 100644 index 0000000..da699b8 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/EventSeverity.java @@ -0,0 +1,37 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +/** + * CEF Event severity or priority + * <p> + * <b>NOTE: Event Severity Enum order must not be changed. Events severity is ordered from high to low</b> + * + * @author Rajiv Singla + */ +public enum EventSeverity implements CEFModel { + + CRITICAL, + MAJOR, + MINOR, + WARNING, + NORMAL + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Field.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Field.java new file mode 100644 index 0000000..070d695 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Field.java @@ -0,0 +1,46 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Name Value Pair + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class Field extends BaseCEFModel { + + private static final long serialVersionUID = 1L; + + /** + * Name of the Field + */ + private String name; + + /** + * Value of the Field + */ + private String value; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/InternalHeaderFields.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/InternalHeaderFields.java new file mode 100644 index 0000000..f886052 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/InternalHeaderFields.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Enrichment fields for internal VES Event Listener service use only, not supplied by event sources + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class InternalHeaderFields extends BaseCEFModel { + + private static final long serialVersionUID = 1L; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/MeasurementsForVfScalingFields.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/MeasurementsForVfScalingFields.java new file mode 100644 index 0000000..ce92132 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/MeasurementsForVfScalingFields.java @@ -0,0 +1,65 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * Common Event Format - MeasurementsForVfScaling fields + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class MeasurementsForVfScalingFields extends BaseCEFModel { + + private static final long serialVersionUID = 1L; + + /** + * Additional name-value-pair fields + */ + private List<Field> additionalFields; + + + /** + * Array of named name-value-pair arrays for additional Measurements + */ + private List<NamedArrayOfFields> additionalMeasurements; + + /** + * Interval over which measurements are being reported in seconds + */ + private Long measurementInterval; + + /** + * Version of the measurementsForVfScaling block + */ + private Float measurementsForVfScalingVersion; + + /** + * Usage of an array of virtual network interface cards + */ + private List<VNicPerformance> vNicPerformanceArray; + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/NamedArrayOfFields.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/NamedArrayOfFields.java new file mode 100644 index 0000000..b7a9530 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/NamedArrayOfFields.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * An array of name value pairs along with a name for the array + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class NamedArrayOfFields extends BaseCEFModel { + + private static final long serialVersionUID = 1L; + + /** + * Name of the NamedArrayOfFields + */ + private String name; + + /** + * Array of name value pairs + */ + private List<Field> arrayOfFields; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/PerformanceCounter.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/PerformanceCounter.java new file mode 100644 index 0000000..8c5fa8c --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/PerformanceCounter.java @@ -0,0 +1,55 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Common Event Format - Performance PerformanceCounter + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class PerformanceCounter extends BaseCEFModel { + + private static final long serialVersionUID = 1L; + + /** + * Performance Counter Criticality. + */ + private Criticality criticality; + + /** + * Performance Counter Name + */ + private String name; + + /** + * Performance Counter for Threshold Crossed. + */ + private String thresholdCrossed; + + /** + * Performance Counter Value. + */ + private String value; +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Priority.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Priority.java new file mode 100644 index 0000000..066af2a --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/Priority.java @@ -0,0 +1,33 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +/** + * Common Event Format - Event processing priority + * + * @author Rajiv Singla + */ +public enum Priority implements CEFModel { + + High, + Medium, + Normal, + Low +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/ThresholdCrossingAlertFields.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/ThresholdCrossingAlertFields.java new file mode 100644 index 0000000..625f5f6 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/ThresholdCrossingAlertFields.java @@ -0,0 +1,113 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * Common Event Format - Fields Specific to threshold crossing alert events + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class ThresholdCrossingAlertFields extends BaseCEFModel { + + private static final long serialVersionUID = 1L; + + /** + * Additional Performance counters parameters. + */ + private List<PerformanceCounter> additionalParameters; + + /** + * Event alert action + */ + private AlertAction alertAction; + + /** + * Unique short alert description such as IF-SHUB-ERRDROP + */ + private String alertDescription; + + /** + * Alert type + */ + private AlertType alertType; + + /** + * Calculated API value (if applicable) + */ + private String alertValue; + + /** + * List of eventIds associated with the event being reported + */ + private List<String> associatedAlertIdList; + + /** + * Time when the performance collector picked up the data; with RFC 2822 compliant format: + * ‘Sat, 13 Mar 2010 11:29:05 -0800’ + */ + private String collectionTimestamp; + + /** + * Specific performance collector instance used + */ + private String dataCollector; + + /** + * Type of network element + */ + private String elementType; + + /** + * 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’ + */ + private String eventStartTimestamp; + + /** + * Physical or logical port or card (if applicable) + */ + private String interfaceName; + + /** + * Network name + */ + private String networkService; + + /** + * Possible Root Cause (reserved for future use) + */ + private String possibleRootCause; + + /** + * Version of the thresholdCrossingAlertFields block + */ + private Integer thresholdCrossingFieldsVersion; +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/VNicPerformance.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/VNicPerformance.java new file mode 100644 index 0000000..d2c774b --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/cef/VNicPerformance.java @@ -0,0 +1,191 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.cef; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Describes the performance and errors of an identified virtual network interface card + * + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class VNicPerformance extends BaseCEFModel { + + + private static final long serialVersionUID = 1L; + + /** + * Cumulative count of broadcast packets received as read at the end of the measurement interval + */ + private Long receivedBroadcastPacketsAccumulated; + + /** + * Count of broadcast packets received within the measurement interval + */ + private Long receivedBroadcastPacketsDelta; + + /** + * Cumulative count of discarded packets received as read at the end of the measurement interval + */ + private Long receivedDiscardedPacketsAccumulated; + + /** + * Count of discarded packets received within the measurement interval + */ + private Long receivedDiscardedPacketsDelta; + + /** + * Cumulative count of error packets received as read at the end of the measurement interval + */ + private Long receivedErrorPacketsAccumulated; + + /** + * Count of error packets received within the measurement interval + */ + private Long receivedErrorPacketsDelta; + + /** + * Cumulative count of multicast packets received as read at the end of the measurement interval + */ + private Long receivedMulticastPacketsAccumulated; + + /** + * Count of multicast packets received within the measurement interval + */ + private Long receivedMulticastPacketsDelta; + + /** + * Cumulative count of octets received as read at the end of the measurement interval + */ + private Long receivedOctetsAccumulated; + + /** + * Count of octets received within the measurement interval + */ + private Long receivedOctetsDelta; + + /** + * Cumulative count of all packets received as read at the end of the measurement interval + */ + private Long receivedTotalPacketsAccumulated; + + /** + * Count of all packets received within the measurement interval + */ + private Long receivedTotalPacketsDelta; + + /** + * Cumulative count of unicast packets received as read at the end of the measurement interval + */ + private Long receivedUnicastPacketsAccumulated; + + /** + * Count of unicast packets received within the measurement interval + */ + private Long receivedUnicastPacketsDelta; + + /** + * Cumulative count of broadcast packets transmitted as read at the end of the measurement interval + */ + private Long transmittedBroadcastPacketsAccumulated; + + /** + * Count of broadcast packets transmitted within the measurement interval + */ + private Long transmittedBroadcastPacketsDelta; + + /** + * Cumulative count of discarded packets transmitted as read at the end of the measurement interval + */ + private Long transmittedDiscardedPacketsAccumulated; + + /** + * Count of discarded packets transmitted within the measurement interval + */ + private Long transmittedDiscardedPacketsDelta; + + /** + * Cumulative count of error packets transmitted as read at the end of the measurement interval + */ + private Long transmittedErrorPacketsAccumulated; + + /** + * Count of error packets transmitted within the measurement interval + */ + private Long transmittedErrorPacketsDelta; + + /** + * Cumulative count of multicast packets transmitted as read at the end of the measurement interval + */ + private Long transmittedMulticastPacketsAccumulated; + + /** + * Count of multicast packets transmitted within the measurement interval + */ + private Long transmittedMulticastPacketsDelta; + + /** + * Cumulative count of octets transmitted as read at the end of the measurement interval + */ + private Long transmittedOctetsAccumulated; + + /** + * Count of octets transmitted within the measurement interval + */ + private Long transmittedOctetsDelta; + + /** + * Cumulative count of all packets transmitted as read at the end of the measurement interval + */ + private Long transmittedTotalPacketsAccumulated; + + /** + * Count of all packets transmitted within the measurement interval + */ + private Long transmittedTotalPacketsDelta; + + /** + * Cumulative count of unicast packets transmitted as read at the end of the measurement interval + */ + private Long transmittedUnicastPacketsAccumulated; + + + /** + * Count of unicast packets transmitted within the measurement interval + */ + private Long transmittedUnicastPacketsDelta; + + + /** + * Indicates whether vNicPerformance values are likely inaccurate due to counter overflow or other conditions + */ + private Boolean valuesAreSuspect; + + + /** + * Virtual Network Card Identifier + */ + private String vNicIdentifier; + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/BaseDynamicPropertiesProvider.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/BaseDynamicPropertiesProvider.java new file mode 100644 index 0000000..8a3f3e4 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/BaseDynamicPropertiesProvider.java @@ -0,0 +1,63 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.common; + +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 accumulated in a map. + * + * @author Rajiv Singla + */ +@Data +public abstract class BaseDynamicPropertiesProvider implements DynamicPropertiesProvider { + + /** + * All non-required properties should be captured in additional properties + */ + private Map<String, Object> dynamicProperties = new LinkedHashMap<>(); + + + /** + * Add a dynamic property to Common Event Format Entity + * + * @param propertyName property name + * @param propertyValue property value + */ + @Override + 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/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/ConfigSource.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/ConfigSource.java new file mode 100644 index 0000000..0829f93 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/ConfigSource.java @@ -0,0 +1,35 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.common; + +import org.onap.dcae.analytics.model.AnalyticsModel; + +/** + * @author Rajiv Singla + */ +public enum ConfigSource implements AnalyticsModel { + + CONFIG_BINDING_SERVICE, + CLASSPATH, + REST_API, + REDIS, + MONGO; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/DynamicPropertiesProvider.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/DynamicPropertiesProvider.java new file mode 100644 index 0000000..ac51656 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/common/DynamicPropertiesProvider.java @@ -0,0 +1,49 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.common; + +import java.io.Serializable; +import java.util.Map; + +/** + * This contract allows the deserialization mechanism to catch dynamic properties + * in a Map so that deserialization mechanism will not loose any information and + * can be serialized back everything without any loss in information + * + * @author Rajiv Singla + */ +public interface DynamicPropertiesProvider extends Serializable { + + + /** + * Adds dynamic properties in a Map object + * + * @param propertyName property name + * @param propertyValue property value + */ + void addDynamicProperties(String propertyName, Object propertyValue); + + /** + * Provides dynamic properties map + * + * @return dynamic properties map object + */ + Map<String, Object> getDynamicProperties(); +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java new file mode 100644 index 0000000..7158b2e --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java @@ -0,0 +1,152 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.configbindingservice; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Base call for Controller Config Binding Service Properties. Other analytics components + * must extend this base class and add properties specific to their requirements + * <p>NOTE: The base class supports all standard config binding service properties and additional custom properties</p> + * + * @author Rajiv Singla + */ +@Data +public abstract class BaseConfigBindingServiceProperties implements ConfigBindingServiceModel { + + private static final long serialVersionUID = 1L; + + protected Map<String, List<String>> servicesCalls = new LinkedHashMap<>(); + protected Map<String, PublisherDetails> streamsPublishes = new LinkedHashMap<>(); + protected Map<String, SubscriberDetails> streamsSubscribes = new LinkedHashMap<>(); + + /** + * Publisher and Subscriber common properties + */ + @Data + @ToString(exclude = "aafPassword") + public static class PubSubCommonDetails implements ConfigBindingServiceModel { + + private static final long serialVersionUID = 1L; + + private String type; + private String aafUsername; + private String aafPassword; + private DmaapInfo dmaapInfo; + + // custom additional properties + private String proxyUrl; + private Boolean ignoreSSLValidation; + + } + + /** + * Publisher Details + */ + @Getter + @Setter + @RequiredArgsConstructor + @ToString(callSuper = true) + @EqualsAndHashCode(callSuper = true) + public static class PublisherDetails extends PubSubCommonDetails { + + private static final long serialVersionUID = 1L; + + } + + + /** + * Subscriber Details + */ + @Getter + @Setter + @RequiredArgsConstructor + @ToString(callSuper = true) + @EqualsAndHashCode(callSuper = true) + public static class SubscriberDetails extends PubSubCommonDetails { + + private static final long serialVersionUID = 1L; + + // custom subscriber properties + private String consumerGroup; + private List<String> consumerIds; + private Integer messageLimit; + private Integer timeout; + + // custom polling configuration + private Polling polling; + } + + /** + * DMaaP Info + */ + @Data + public static class DmaapInfo implements ConfigBindingServiceModel { + + private static final long serialVersionUID = 1L; + + private String clientRole; + private String clientId; + private String location; + private String topicUrl; + + } + + + /** + * Polling Details + */ + @Data + public static class Polling implements ConfigBindingServiceModel { + + private static final long serialVersionUID = 1L; + + private Integer fixedRate; + private AutoAdjusting autoAdjusting; + + } + + + /** + * Auto Adjusting Polling Details + */ + @Data + public static class AutoAdjusting implements ConfigBindingServiceModel { + + private static final long serialVersionUID = 1L; + + private Integer min; + private Integer stepUp; + private Integer max; + private Integer stepDown; + + } + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java new file mode 100644 index 0000000..196b791 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java @@ -0,0 +1,68 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.configbindingservice; + +import java.util.Map; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.onap.dcae.analytics.model.configbindingservice.BaseConfigBindingServiceProperties.PubSubCommonDetails; + +/** + * @author Rajiv Singla + */ +public abstract class ConfigBindingServiceConstants { + + // ================== CONFIG SERVICE CONSTANTS ============================== // + public static final String CONSUL_HOST_ENV_VARIABLE_KEY = "CONSUL_HOST"; + public static final String CONSUL_HOST_ENV_VARIABLE_VALUE = System.getenv(CONSUL_HOST_ENV_VARIABLE_KEY); + public static final String CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY = "CONFIG_BINDING_SERVICE"; + public static final String CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE = + System.getenv(CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY); + public static final String SERVICE_NAME_ENV_VARIABLE_KEY = "SERVICE_NAME"; + public static final String SERVICE_NAME_ENV_VARIABLE_VALUE = System.getenv(SERVICE_NAME_ENV_VARIABLE_KEY); + public static final String CONSUL_QUERY_URL_STRING = String.format("http://%s:8500/v1/catalog/service/%s", + CONSUL_HOST_ENV_VARIABLE_VALUE, CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE); + public static final String CONFIG_SERVICE_QUERY_URL_STRING = "http://%s:%s/service_component/%s"; + + + public static final String CONFIG_BINDING_SERVICE_PROPERTIES_KEY = "config-binding-service"; + + + public static final Set<String> SPRING_RESERVED_PROPERTIES_KEY_PREFIXES = + Stream.of("spring", "endpoints", "server", "logging", "management").collect(Collectors.toSet()); + public static final String CONFIG_SERVICE_MESSAGE_ROUTER_VALUE = "message_router"; + // CONVERT JSON TO MAP + public static final String KEY_SEPARATOR = "."; + + // ============== CONFIG BINDING SERVICE UTILS ========================= // + /** + * Predicate which can be used to filter message router publisher or subscriber details + */ + public static final Predicate<Map.Entry<String, ? extends PubSubCommonDetails>> MESSAGE_ROUTER_PREDICATE = + e -> e.getValue().getType() != null && + e.getValue().getType().equalsIgnoreCase(CONFIG_SERVICE_MESSAGE_ROUTER_VALUE); + + private ConfigBindingServiceConstants() { + // private constructor + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceModel.java new file mode 100644 index 0000000..902dded --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceModel.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.configbindingservice; + +import org.onap.dcae.analytics.model.AnalyticsModel; + +/** + * Marker Interface for all Config Binding Service Model Objects + * + * @author Rajiv Singla + */ +public interface ConfigBindingServiceModel extends AnalyticsModel { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConsulConfigBindingServiceQueryResponse.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConsulConfigBindingServiceQueryResponse.java new file mode 100644 index 0000000..fed262e --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConsulConfigBindingServiceQueryResponse.java @@ -0,0 +1,55 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.configbindingservice; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; +import java.util.Map; + +import org.onap.dcae.analytics.model.common.BaseDynamicPropertiesProvider; + +/** + * @author Rajiv Singla + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class ConsulConfigBindingServiceQueryResponse extends BaseDynamicPropertiesProvider implements + ConfigBindingServiceModel { + + private static final long serialVersionUID = 1L; + + private String id; + private String node; + private String address; + private String dataCenter; + private Map<String, String> taggedAddresses; + private Map<String, String> nodeMeta; + private String serviceId; + private String serviceName; + private List<String> serviceTags; + private String serviceAddress; + private Integer servicePort; + private Boolean serviceEnableTagOverride; + private long createIndex; + private long modifyIndex; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorType.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorType.java new file mode 100644 index 0000000..0cf306c --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/ecomplogger/AnalyticsErrorType.java @@ -0,0 +1,50 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.ecomplogger; + +/** + * @author Rajiv Singla + */ +public enum AnalyticsErrorType implements EcompLoggerModel { + + SUCCESSFUL(0, ""), + PERMISSION_ERROR(100, "Permission Error"), + TIMEOUT_ERROR(200, "Timeout Error"), + DATA_ERROR(300, "Data Error"), + SCHEMA_ERROR(400, "Schema Error"), + BUSINESS_PROCESS_ERROR(500, "Business Process Error"), + UNKNOWN_ERROR(900, "Unknown Error"); + + private final Integer errorCode; + private final String errorDescription; + + AnalyticsErrorType(final Integer errorCode, final String errorDescription) { + this.errorCode = errorCode; + this.errorDescription = errorDescription; + } + + public Integer getErrorCode() { + return errorCode; + } + + public String getErrorDescription() { + return errorDescription; + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/ecomplogger/EcompLoggerModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/ecomplogger/EcompLoggerModel.java new file mode 100644 index 0000000..9ff2736 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/ecomplogger/EcompLoggerModel.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.ecomplogger; + +import org.onap.dcae.analytics.model.AnalyticsModel; + +/** + * Marker interface for all ECOMP Logger Model classes + * + * @author Rajiv Singla + */ +public interface EcompLoggerModel extends AnalyticsModel { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/facade/AnalyticsFacadeModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/facade/AnalyticsFacadeModel.java new file mode 100644 index 0000000..75f0321 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/facade/AnalyticsFacadeModel.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.facade; + +import org.onap.dcae.analytics.model.AnalyticsModel; + +/** + * Marker Interface for all Facade (outgoing) DCAE Analytics Facade Models + * + * @author Rajiv Singla + */ +public interface AnalyticsFacadeModel extends AnalyticsModel { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/policy/AnalyticsPolicyModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/policy/AnalyticsPolicyModel.java new file mode 100644 index 0000000..baebfbc --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/policy/AnalyticsPolicyModel.java @@ -0,0 +1,32 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.policy; + +import org.onap.dcae.analytics.model.AnalyticsModel; + +/** + * Marker Interface all DCAE Analytics Policy Model implementations + * + * @author Rajiv Singla + */ +public interface AnalyticsPolicyModel extends AnalyticsModel { + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/BiFunctionExtension.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/BiFunctionExtension.java new file mode 100644 index 0000000..1a3779a --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/BiFunctionExtension.java @@ -0,0 +1,47 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.function; + +import java.util.function.BiFunction; +import java.util.function.Function; + +/** + * A BiFunction extension which extends {@link BiFunction} to support additional functional + * concepts like currying + * + * @param <T> the type of the first argument to the function + * @param <U> the type of the second argument to the function + * @param <R> the type of the result of the function + */ +public interface BiFunctionExtension<T, U, R> extends BiFunction<T, U, R> { + + /** + * Returns a {@link Function} which takes one argument + * + * @param t Bi Function first param + * + * @return Function which takes another argument + */ + default Function<U, R> curry(T t) { + return (U u) -> apply(t, u); + } + +} + diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunction.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunction.java new file mode 100644 index 0000000..a68c327 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/JsonStringToMapFunction.java @@ -0,0 +1,169 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.function; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; + +import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Converts JSON String to flatten map of key value pair + * + * @author Rajiv Singla + */ +public class JsonStringToMapFunction implements Function<String, Map<String, Object>> { + + private static final Logger logger = LoggerFactory.getLogger(JsonStringToMapFunction.class); + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private final String keyPrefix; + private final String keySeparator; + + public JsonStringToMapFunction(final String keyPrefix, final String keySeparator) { + this.keyPrefix = keyPrefix; + this.keySeparator = keySeparator; + } + + public JsonStringToMapFunction(final String keyPrefix) { + this(keyPrefix, ConfigBindingServiceConstants.KEY_SEPARATOR); + } + + public JsonStringToMapFunction() { + this("", ConfigBindingServiceConstants.KEY_SEPARATOR); + } + + @Override + @SuppressWarnings("unchecked") + public Map<String, Object> apply(final String jsonString) { + + logger.debug("Converting JSON to flattened key value Map: {}", jsonString); + if (jsonString == null || jsonString.trim().isEmpty()) { + return new HashMap<>(); + } + + final Map<String, Object> result = flattenJson(jsonString); + logger.debug("Flattened Key Value Pairs"); + result.forEach((key, value) -> logger.debug("{}:{}", key, value)); + return result; + } + + /** + * Flattens Json String + * + * @param jsonString json String + * + * @return map containing flattened json string key and value + */ + private Map<String, Object> flattenJson(final String jsonString) { + + try { + final JsonNode rootNode = OBJECT_MAPPER.readTree(jsonString); + final LinkedHashMap<String, Object> result = new LinkedHashMap<>(); + flattenJsonNode(keyPrefix, rootNode, result); + return result; + } catch (IOException e) { + final String errorMessage = String.format("Unable to flatten JSON String to Map. Invalid JSON String: " + + "%s", jsonString); + logger.error(errorMessage, e, jsonString); + throw new IllegalArgumentException(jsonString, e); + } + + } + + /** + * Flattens json array + * + * @param propertyPrefix property prefix + * @param jsonNodesIterator json array node that needs to be flattened + * @param resultMap result map containing flattened key value pairs + */ + private void flattenJsonArray(String propertyPrefix, Iterator<JsonNode> jsonNodesIterator, + Map<String, Object> resultMap) { + int counter = 0; + while (jsonNodesIterator.hasNext()) { + flattenJsonNode(propertyPrefix + "[" + counter + "]", jsonNodesIterator.next(), resultMap); + counter++; + } + + } + + /** + * Flattens json array + * + * @param propertyPrefix property prefix + * @param objectNode json object node that needs to be flattened + * @param resultMap result map containing flattened key value pairs + */ + private void flattenJsonMap(String propertyPrefix, JsonNode objectNode, + Map<String, Object> resultMap) { + final Iterator<Map.Entry<String, JsonNode>> fieldsIterator = objectNode.fields(); + while (fieldsIterator.hasNext()) { + final Map.Entry<String, JsonNode> fieldEntry = fieldsIterator.next(); + final JsonNode jsonValue = fieldEntry.getValue(); + final String jsonKey = fieldEntry.getKey(); + flattenJsonNode( + (propertyPrefix.isEmpty() ? "" : propertyPrefix + keySeparator) + jsonKey, + jsonValue, resultMap); + } + } + + /** + * Checks various elements types of JSON Types and flattens them based on their type + * + * @param propertyPrefix property prefix + * @param currentJsonNode currentJsonNode that may need to be flattened + * @param resultMap result map containing flattened key value pairs + */ + private void flattenJsonNode(final String propertyPrefix, final JsonNode currentJsonNode, + final Map<String, Object> resultMap) { + + + if (currentJsonNode.isObject()) { + flattenJsonMap(propertyPrefix, currentJsonNode, resultMap); + } else if (currentJsonNode.isArray()) { + flattenJsonArray(propertyPrefix, currentJsonNode.iterator(), resultMap); + } else { + resultMap.put(propertyPrefix, getObjectValue(currentJsonNode)); + } + } + + private static Object getObjectValue(final JsonNode jsonNode) { + if (jsonNode.isTextual()) { + return jsonNode.textValue(); + } else if (jsonNode.isNumber()) { + return jsonNode.asLong(); + } else if (jsonNode.isBoolean()) { + return jsonNode.asBoolean(); + } else { + return jsonNode.asText(); + } + } +} + diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunction.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunction.java new file mode 100644 index 0000000..7910435 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/JsonToJavaObjectBiFunction.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.function; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Converts given Json String to Java Object if possible + * + * @param <T> Target Java Object class Type for JSON String + * + * @author Rajiv Singla + */ +public class JsonToJavaObjectBiFunction<T> implements BiFunctionExtension<TypeReference<T>, String, Optional<T>> { + + private static final Logger logger = LoggerFactory.getLogger(JsonToJavaObjectBiFunction.class); + + private final ObjectMapper objectMapper; + + public JsonToJavaObjectBiFunction(final ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + + @Override + public Optional<T> apply(final TypeReference<T> typeReference, final String jsonString) { + + try { + return Optional.of(objectMapper.readValue(jsonString, typeReference)); + } catch (IOException e) { + logger.error("Unable to convert given JSON String to Java Object. JSON String: " + jsonString, e); + } + + return Optional.empty(); + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/StringToURLFunction.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/StringToURLFunction.java new file mode 100644 index 0000000..18f5cd5 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/StringToURLFunction.java @@ -0,0 +1,50 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.function; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Optional; +import java.util.function.Function; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Converts String to URL if possible + * + * @author Rajiv Singla + */ +public class StringToURLFunction implements Function<String, Optional<URL>> { + + private static final Logger logger = LoggerFactory.getLogger(StringToURLFunction.class); + + @Override + public Optional<URL> apply(final String urlString) { + + try { + return Optional.of(new URL(urlString)); + } catch (MalformedURLException e) { + logger.error("Unable to convert given String: {} to URL" + urlString, e); + } + + return Optional.empty(); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunction.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunction.java new file mode 100644 index 0000000..fe5ae07 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/function/URLToHttpGetFunction.java @@ -0,0 +1,77 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.function; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Optional; +import java.util.Scanner; +import java.util.function.Function; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Simple Function that calls http 'GET' on given URL and returns the response as String if successful. This function + * has side effects and only used for convenience in lambda expressions + * <p> + * NOTE: Suitable for only light weight http get requests as this will be a blocking call + * + * @author Rajiv Singla + */ +public class URLToHttpGetFunction implements Function<URL, Optional<String>> { + + private static final Logger logger = LoggerFactory.getLogger(URLToHttpGetFunction.class); + + @Override + public Optional<String> apply(final URL url) { + + try { + final HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); + httpConnection.setRequestMethod("GET"); + + logger.info("Sending 'GET' request to URL : {}", url); + final int responseCode = httpConnection.getResponseCode(); + + if (responseCode == 200) { + final StringBuilder responseString = new StringBuilder(); + try (Scanner scanner = new Scanner(httpConnection.getInputStream(), StandardCharsets.UTF_8.name())) { + while (scanner.hasNext()) { + responseString.append(scanner.next()); + } + } + + logger.info("Successful Response: {}", responseString); + return Optional.of(responseString.toString()); + } + + logger.error("Unsuccessful Response Code: {} when calling URL: {}", responseCode, url); + + } catch (IOException e) { + + logger.error("Unable to create HTTP URL Connection to URL:" + url, e); + + } + + return Optional.empty(); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/AnalyticsModelJsonConversion.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/AnalyticsModelJsonConversion.java new file mode 100644 index 0000000..3ba3fe8 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/AnalyticsModelJsonConversion.java @@ -0,0 +1,77 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +import org.onap.dcae.analytics.model.cef.EventListener; +import org.onap.dcae.analytics.model.configbindingservice.ConsulConfigBindingServiceQueryResponse; +import org.onap.dcae.analytics.model.util.function.JsonToJavaObjectBiFunction; + +/** + * @author Rajiv Singla + */ +public abstract class AnalyticsModelJsonConversion { + + public static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER = new BaseObjectMapperSupplier() { + @Override + public void registerCustomModules(final ObjectMapper objectMapper) { + // do nothing + } + }.get(); + + // Type reference to convert a list or array of Config Service Binding + private static final TypeReference<List<ConsulConfigBindingServiceQueryResponse>> + CONFIG_BINDING_SERVICE_LIST_TYPE_REF = new TypeReference<List<ConsulConfigBindingServiceQueryResponse>>() { + }; + // Type reference to convert a list or array of event listener list + private static final TypeReference<List<EventListener>> EVENT_LISTENER_LIST_TYPE_REF = + new TypeReference<List<EventListener>>() { + }; + // Type reference to convert single event listener + private static final TypeReference<EventListener> EVENT_LISTENER_TYPE_REF = new TypeReference<EventListener>() { + }; + + + // Event Listener Json Conversion Function + public static final Function<String, Optional<EventListener>> EVENT_LISTENER_JSON_FUNCTION = + new JsonToJavaObjectBiFunction<EventListener>(ANALYTICS_MODEL_OBJECT_MAPPER) + .curry(EVENT_LISTENER_TYPE_REF); + + // Event Listener List Json Conversion Function + public static final Function<String, Optional<List<EventListener>>> EVENT_LISTENER_LIST_JSON_FUNCTION = + new JsonToJavaObjectBiFunction<List<EventListener>>(ANALYTICS_MODEL_OBJECT_MAPPER) + .curry(EVENT_LISTENER_LIST_TYPE_REF); + + // Consul Config Binding Service Query Json Conversion Function + public static final Function<String, Optional<List<ConsulConfigBindingServiceQueryResponse>>> + CONFIG_BINDING_SERVICE_LIST_JSON_FUNCTION = new + JsonToJavaObjectBiFunction<List<ConsulConfigBindingServiceQueryResponse>>(ANALYTICS_MODEL_OBJECT_MAPPER) + .curry(CONFIG_BINDING_SERVICE_LIST_TYPE_REF); + + private AnalyticsModelJsonConversion() { + // private constructor + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/BaseObjectMapperSupplier.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/BaseObjectMapperSupplier.java new file mode 100644 index 0000000..18e8262 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/BaseObjectMapperSupplier.java @@ -0,0 +1,125 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.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.jayway.jsonpath.Configuration; +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 java.util.EnumSet; +import java.util.Set; +import java.util.function.Supplier; + +import org.onap.dcae.analytics.model.util.json.module.CommonEventFormatModule; +import org.onap.dcae.analytics.model.util.json.module.ConfigBindingServiceModule; +import org.onap.dcae.analytics.model.util.json.module.DynamicPropertiesModule; + +/** + * Base Object mapper supplies Jackson {@link ObjectMapper} that specializes in serialize and deserialize - + * Analytics model objects. Various analytics components should inherit from this supplier and register + * their custom modules + * + * @author Rajiv Singla + */ +public abstract class BaseObjectMapperSupplier implements Supplier<ObjectMapper> { + + /** + * Class that can used to configure Json Path configuration + */ + public static class JsonPathConfiguration implements Configuration.Defaults { + + private final JsonProvider jsonProvider; + private final MappingProvider mappingProvider; + private final Set<Option> options; + + private JsonPathConfiguration(final ObjectMapper objectMapper, final Set<Option> options) { + jsonProvider = new JacksonJsonProvider(objectMapper); + mappingProvider = new JacksonMappingProvider(objectMapper); + this.options = options; + } + + + @Override + public JsonProvider jsonProvider() { + return jsonProvider; + } + + @Override + public Set<Option> options() { + return options; + } + + @Override + public MappingProvider mappingProvider() { + return mappingProvider; + } + } + + public abstract void registerCustomModules(final ObjectMapper objectMapper); + + @Override + public ObjectMapper get() { + + final ObjectMapper objectMapper = new ObjectMapper(); + + // Ignore null values during serialization. Null values will not be included in serialized JSON object + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + // Don't fail on unknown properties + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + // register dynamic properties module + objectMapper.registerModule(new DynamicPropertiesModule()); + // register config binding service module + objectMapper.registerModule(new ConfigBindingServiceModule()); + // register common event format module + objectMapper.registerModule(new CommonEventFormatModule()); + + // register custom modules + registerCustomModules(objectMapper); + + // Setup JsonPath default config + setupJsonPathDefaultConfig(objectMapper); + + return objectMapper; + } + + /** + * Setups up default Config for Json Path + * + * @param objectMapper Jackson object mapper + */ + private void setupJsonPathDefaultConfig(final ObjectMapper objectMapper) { + + Configuration.setDefaults(new JsonPathConfiguration(objectMapper, EnumSet.of( + Option.DEFAULT_PATH_LEAF_TO_NULL, // missing properties are tolerated + Option.SUPPRESS_EXCEPTIONS, // Json Path exceptions are suppressed + Option.ALWAYS_RETURN_LIST // always return results as list + )) + ); + + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/JsonMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/JsonMixin.java new file mode 100644 index 0000000..99ab7c9 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/JsonMixin.java @@ -0,0 +1,30 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin; + +import java.io.Serializable; + +/** + * Marker Interface for all Json Mixin classes + * + * @author Rajiv Singla + */ +public interface JsonMixin extends Serializable { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertActionMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertActionMixin.java new file mode 100644 index 0000000..d1170a5 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertActionMixin.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * @author Rajiv Singla + */ +public abstract class AlertActionMixin implements JsonMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixin.java new file mode 100644 index 0000000..da625ea --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixin.java @@ -0,0 +1,61 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import org.onap.dcae.analytics.model.cef.AlertType; +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * Mixin for Alert Type + * + * @author Rajiv Singla + */ +public abstract class AlertTypeMixin implements JsonMixin { + + private String name; + + @JsonCreator + public static AlertType forValue(String name) { + + switch (name) { + case "CARD-ANOMALY": + return AlertType.CARD_ANOMALY; + case "ELEMENT-ANOMALY": + return AlertType.ELEMENT_ANOMALY; + case "INTERFACE-ANOMALY": + return AlertType.INTERFACE_ANOMALY; + case "SERVICE-ANOMALY": + return AlertType.SERVICE_ANOMALY; + default: + return AlertType.UNKNOWN; + } + + } + + @JsonValue + public String getName() { + return name; + } + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/BaseCEFModelMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/BaseCEFModelMixin.java new file mode 100644 index 0000000..2ea82ed --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/BaseCEFModelMixin.java @@ -0,0 +1,31 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + + +import org.onap.dcae.analytics.model.util.json.mixin.common.BaseDynamicPropertiesProviderMixin; + +/** + * Abstract Mixin for all CEF Model Mixins + * + * @author Rajiv Singla + */ +public abstract class BaseCEFModelMixin extends BaseDynamicPropertiesProviderMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CommonEventHeaderMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CommonEventHeaderMixin.java new file mode 100644 index 0000000..b4b8eb2 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CommonEventHeaderMixin.java @@ -0,0 +1,26 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * @author Rajiv Singla + */ +public abstract class CommonEventHeaderMixin extends BaseCEFModelMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityMixin.java new file mode 100644 index 0000000..09fd095 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/CriticalityMixin.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * @author Rajiv Singla + */ +public abstract class CriticalityMixin implements JsonMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/DomainMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/DomainMixin.java new file mode 100644 index 0000000..fdceb21 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/DomainMixin.java @@ -0,0 +1,29 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * @author Rajiv Singla + */ +public abstract class DomainMixin implements JsonMixin { + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventListenerMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventListenerMixin.java new file mode 100644 index 0000000..061a308 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventListenerMixin.java @@ -0,0 +1,29 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * Event Listener Json Mixin class + * <p> + * + * @author Rajiv Singla + */ +public abstract class EventListenerMixin extends BaseCEFModelMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventMixin.java new file mode 100644 index 0000000..5a73244 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventMixin.java @@ -0,0 +1,29 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * Event Json Mixin class + * <p> + * + * @author Rajiv Singla + */ +public abstract class EventMixin extends BaseCEFModelMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventSeverityMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventSeverityMixin.java new file mode 100644 index 0000000..a7ca8a7 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventSeverityMixin.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * @author Rajiv Singla + */ +public abstract class EventSeverityMixin implements JsonMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/FieldMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/FieldMixin.java new file mode 100644 index 0000000..a9561ab --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/FieldMixin.java @@ -0,0 +1,27 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * @author Rajiv Singla + */ +public abstract class FieldMixin extends BaseCEFModelMixin { + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/InternalHeaderFieldsMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/InternalHeaderFieldsMixin.java new file mode 100644 index 0000000..d121842 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/InternalHeaderFieldsMixin.java @@ -0,0 +1,27 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * @author Rajiv Singla + */ +public abstract class InternalHeaderFieldsMixin extends BaseCEFModelMixin { + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/MeasurementsForVfScalingFieldsMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/MeasurementsForVfScalingFieldsMixin.java new file mode 100644 index 0000000..eda527a --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/MeasurementsForVfScalingFieldsMixin.java @@ -0,0 +1,39 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonSetter; + +import java.util.List; + +import org.onap.dcae.analytics.model.cef.VNicPerformance; + +/** + * @author Rajiv Singla + */ +public abstract class MeasurementsForVfScalingFieldsMixin extends BaseCEFModelMixin { + + @JsonGetter("vNicPerformanceArray") + public abstract List<VNicPerformance> getVNicPerformanceArray(); + + @JsonSetter("vNicPerformanceArray") + public abstract void setVNicPerformanceArray(List<VNicPerformance> vNicPerformances); +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/NamedArrayOfFieldsMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/NamedArrayOfFieldsMixin.java new file mode 100644 index 0000000..f23b803 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/NamedArrayOfFieldsMixin.java @@ -0,0 +1,27 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * @author Rajiv Singla + */ +public abstract class NamedArrayOfFieldsMixin extends BaseCEFModelMixin { + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/PerformanceCounterMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/PerformanceCounterMixin.java new file mode 100644 index 0000000..dd7ed61 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/PerformanceCounterMixin.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * CEF Performance Counter Mixin + * + * @author Rajiv Singla + */ +public abstract class PerformanceCounterMixin extends BaseCEFModelMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/PriorityMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/PriorityMixin.java new file mode 100644 index 0000000..c36658e --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/PriorityMixin.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * @author Rajiv Singla + */ +public abstract class PriorityMixin implements JsonMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/ThresholdCrossingAlertFieldsMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/ThresholdCrossingAlertFieldsMixin.java new file mode 100644 index 0000000..ce4a129 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/ThresholdCrossingAlertFieldsMixin.java @@ -0,0 +1,28 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +/** + * Mixin class for ThresholdCrossingAlertFields + * + * @author Rajiv Singla + */ +public abstract class ThresholdCrossingAlertFieldsMixin extends BaseCEFModelMixin { +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/VNicUsageArrayMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/VNicUsageArrayMixin.java new file mode 100644 index 0000000..6152d7f --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/cef/VNicUsageArrayMixin.java @@ -0,0 +1,35 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import com.fasterxml.jackson.annotation.JsonSetter; + +/** + * @author Rajiv Singla + */ +public abstract class VNicUsageArrayMixin extends BaseCEFModelMixin { + + @JsonSetter("vNicIdentifier") + public abstract void setVNicIdentifier(String name); + + @JsonSetter("vNicIdentifier") + public abstract String setVNicIdentifier(); + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/common/BaseDynamicPropertiesProviderMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/common/BaseDynamicPropertiesProviderMixin.java new file mode 100644 index 0000000..b4cd525 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/common/BaseDynamicPropertiesProviderMixin.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.common; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; + +import java.util.Map; + +import org.onap.dcae.analytics.model.common.BaseDynamicPropertiesProvider; +import org.onap.dcae.analytics.model.util.json.mixin.JsonMixin; + +/** + * Json Mixin for {@link BaseDynamicPropertiesProvider} + * + * @author Rajiv Singla + */ +public abstract class BaseDynamicPropertiesProviderMixin implements JsonMixin { + + /** + * Provides hint to Jackson Json Object mapper to bind any put all dynamic properties in a map + * + * @param propertyName dynamic property name + * @param propertyValue dynamic property value + */ + @JsonAnySetter + public abstract void addDynamicProperties(String propertyName, Object propertyValue); + + /** + * Provides hint to serialize dynamic properties as map + * + * @return dynamic properties map + */ + @JsonAnyGetter + public abstract Map<String, Object> getDynamicProperties(); + + /** + * Ignores isDynamicPropertiesPresent for json serialization + * + * @return true if dynamic properties are present + */ + @JsonIgnore + public abstract boolean isDynamicPropertiesPresent(); +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/configbindingservice/ConsulConfigBindingServiceQueryResponseMixin.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/configbindingservice/ConsulConfigBindingServiceQueryResponseMixin.java new file mode 100644 index 0000000..e1da351 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/mixin/configbindingservice/ConsulConfigBindingServiceQueryResponseMixin.java @@ -0,0 +1,63 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.configbindingservice; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; +import java.util.Map; + +import org.onap.dcae.analytics.model.util.json.mixin.common.BaseDynamicPropertiesProviderMixin; + +/** + * @author Rajiv Singla + */ +public abstract class ConsulConfigBindingServiceQueryResponseMixin extends BaseDynamicPropertiesProviderMixin { + + @JsonProperty("ID") + private String id; + @JsonProperty("Node") + private String node; + @JsonProperty("Address") + private String address; + @JsonProperty("Datacenter") + private String dataCenter; + @JsonProperty("TaggedAddresses") + private Map<String, String> taggedAddresses; + @JsonProperty("NodeMeta") + private Map<String, String> nodeMeta; + @JsonProperty("ServiceID") + private String serviceId; + @JsonProperty("ServiceName") + private String serviceName; + @JsonProperty("ServiceTags") + private List<String> serviceTags; + @JsonProperty("ServiceAddress") + private String serviceAddress; + @JsonProperty("ServicePort") + private Integer servicePort; + @JsonProperty("ServiceEnableTagOverride") + private Boolean serviceEnableTagOverride; + @JsonProperty("CreateIndex") + private long createIndex; + @JsonProperty("ModifyIndex") + private long modifyIndex; + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/CommonEventFormatModule.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/CommonEventFormatModule.java new file mode 100644 index 0000000..1daf2ef --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/CommonEventFormatModule.java @@ -0,0 +1,100 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.module; + +import static org.onap.dcae.analytics.model.AnalyticsModelConstants.JSON_MODULE_ARTIFACT_ID; +import static org.onap.dcae.analytics.model.AnalyticsModelConstants.JSON_MODULE_GROUP_ID; + +import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.module.SimpleModule; + +import org.onap.dcae.analytics.model.cef.AlertAction; +import org.onap.dcae.analytics.model.cef.AlertType; +import org.onap.dcae.analytics.model.cef.BaseCEFModel; +import org.onap.dcae.analytics.model.cef.CommonEventHeader; +import org.onap.dcae.analytics.model.cef.Criticality; +import org.onap.dcae.analytics.model.cef.Domain; +import org.onap.dcae.analytics.model.cef.Event; +import org.onap.dcae.analytics.model.cef.EventListener; +import org.onap.dcae.analytics.model.cef.EventSeverity; +import org.onap.dcae.analytics.model.cef.Field; +import org.onap.dcae.analytics.model.cef.InternalHeaderFields; +import org.onap.dcae.analytics.model.cef.MeasurementsForVfScalingFields; +import org.onap.dcae.analytics.model.cef.NamedArrayOfFields; +import org.onap.dcae.analytics.model.cef.PerformanceCounter; +import org.onap.dcae.analytics.model.cef.Priority; +import org.onap.dcae.analytics.model.cef.ThresholdCrossingAlertFields; +import org.onap.dcae.analytics.model.cef.VNicPerformance; +import org.onap.dcae.analytics.model.util.json.mixin.cef.AlertActionMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.AlertTypeMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.BaseCEFModelMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.CommonEventHeaderMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.CriticalityMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.DomainMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.EventListenerMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.EventMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.EventSeverityMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.FieldMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.InternalHeaderFieldsMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.MeasurementsForVfScalingFieldsMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.NamedArrayOfFieldsMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.PerformanceCounterMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.PriorityMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.ThresholdCrossingAlertFieldsMixin; +import org.onap.dcae.analytics.model.util.json.mixin.cef.VNicUsageArrayMixin; + + +/** + * @author Rajiv Singla + */ +public class CommonEventFormatModule extends SimpleModule { + + private static final long serialVersionUID = 1L; + + public CommonEventFormatModule() { + super("Common Event Format", + new Version(28, 3, 0, null, JSON_MODULE_GROUP_ID, JSON_MODULE_ARTIFACT_ID)); + } + + @Override + public void setupModule(final SetupContext setupContext) { + + setupContext.setMixInAnnotations(AlertAction.class, AlertActionMixin.class); + setupContext.setMixInAnnotations(AlertType.class, AlertTypeMixin.class); + setupContext.setMixInAnnotations(BaseCEFModel.class, BaseCEFModelMixin.class); + setupContext.setMixInAnnotations(CommonEventHeader.class, CommonEventHeaderMixin.class); + setupContext.setMixInAnnotations(Domain.class, DomainMixin.class); + setupContext.setMixInAnnotations(InternalHeaderFields.class, InternalHeaderFieldsMixin.class); + setupContext.setMixInAnnotations(Field.class, FieldMixin.class); + setupContext.setMixInAnnotations(NamedArrayOfFields.class, NamedArrayOfFieldsMixin.class); + setupContext.setMixInAnnotations(Criticality.class, CriticalityMixin.class); + setupContext.setMixInAnnotations(EventListener.class, EventListenerMixin.class); + setupContext.setMixInAnnotations(Event.class, EventMixin.class); + setupContext.setMixInAnnotations(EventSeverity.class, EventSeverityMixin.class); + setupContext.setMixInAnnotations(MeasurementsForVfScalingFields.class, + MeasurementsForVfScalingFieldsMixin.class); + setupContext.setMixInAnnotations(PerformanceCounter.class, PerformanceCounterMixin.class); + setupContext.setMixInAnnotations(Priority.class, PriorityMixin.class); + setupContext.setMixInAnnotations(ThresholdCrossingAlertFields.class, ThresholdCrossingAlertFieldsMixin.class); + setupContext.setMixInAnnotations(VNicPerformance.class, VNicUsageArrayMixin.class); + + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/ConfigBindingServiceModule.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/ConfigBindingServiceModule.java new file mode 100644 index 0000000..19845d1 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/ConfigBindingServiceModule.java @@ -0,0 +1,40 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.module; + +import com.fasterxml.jackson.databind.module.SimpleModule; + +import org.onap.dcae.analytics.model.configbindingservice.ConsulConfigBindingServiceQueryResponse; +import org.onap.dcae.analytics.model.util.json.mixin.configbindingservice.ConsulConfigBindingServiceQueryResponseMixin; + + +/** + * @author Rajiv Singla + */ +public class ConfigBindingServiceModule extends SimpleModule { + + private static final long serialVersionUID = 1L; + + @Override + public void setupModule(final SetupContext setupContext) { + setupContext.setMixInAnnotations(ConsulConfigBindingServiceQueryResponse.class, + ConsulConfigBindingServiceQueryResponseMixin.class); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/DynamicPropertiesModule.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/DynamicPropertiesModule.java new file mode 100644 index 0000000..a555023 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/json/module/DynamicPropertiesModule.java @@ -0,0 +1,38 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.module; + +import com.fasterxml.jackson.databind.module.SimpleModule; + +import org.onap.dcae.analytics.model.common.BaseDynamicPropertiesProvider; +import org.onap.dcae.analytics.model.util.json.mixin.common.BaseDynamicPropertiesProviderMixin; + +/** + * @author Rajiv Singla + */ +public class DynamicPropertiesModule extends SimpleModule { + + private static final long serialVersionUID = 1L; + + @Override + public void setupModule(final SetupContext setupContext) { + setupContext.setMixInAnnotations(BaseDynamicPropertiesProvider.class, BaseDynamicPropertiesProviderMixin.class); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplier.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplier.java new file mode 100644 index 0000000..f359ff4 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/AnalyticsRequestIdSupplier.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.supplier; + +import java.util.UUID; +import java.util.function.Supplier; + +/** + * Generates new Request id for Analytics ECOMP Components + * + * @author Rajiv Singla + */ +public class AnalyticsRequestIdSupplier implements Supplier<String> { + + @Override + public String get() { + return UUID.randomUUID().toString(); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/ConfigBindingServiceJsonSupplier.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/ConfigBindingServiceJsonSupplier.java new file mode 100644 index 0000000..b882bb0 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/ConfigBindingServiceJsonSupplier.java @@ -0,0 +1,128 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.supplier; + + +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; + +import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants; +import org.onap.dcae.analytics.model.configbindingservice.ConsulConfigBindingServiceQueryResponse; +import org.onap.dcae.analytics.model.util.function.StringToURLFunction; +import org.onap.dcae.analytics.model.util.function.URLToHttpGetFunction; +import org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A Function which fetches ApplicationProperties configuration from + * Config Binding Service when deployed via docker, typically during application startup time. + * + * @author Rajiv Singla + */ +public class ConfigBindingServiceJsonSupplier implements Supplier<Optional<String>> { + + private static final Logger logger = LoggerFactory.getLogger(ConfigBindingServiceJsonSupplier.class); + + private final Function<String, Optional<String>> fetchUrlContentFunction; + + public ConfigBindingServiceJsonSupplier(final Function<String, Optional<String>> fetchUrlContentFunction) { + this.fetchUrlContentFunction = fetchUrlContentFunction; + } + + public ConfigBindingServiceJsonSupplier() { + fetchUrlContentFunction = (String s) -> new StringToURLFunction().apply(s).flatMap(new URLToHttpGetFunction()); + } + + @Override + public Optional<String> get() { + + logger.info("Consul Host Environment Variable: {}", + ConfigBindingServiceConstants.CONSUL_HOST_ENV_VARIABLE_VALUE); + logger.info("Config Binding Service Environment Variable: {}", + ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE); + logger.info("Service Name Environment Variable: {}", + ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE); + + if (ConfigBindingServiceConstants.CONSUL_HOST_ENV_VARIABLE_VALUE == null || + ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE == null || + ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE == null) { + logger.error("Environment variables required to query Config Binding Service are not present"); + return Optional.empty(); + } + + return Optional.of(ConfigBindingServiceConstants.CONSUL_QUERY_URL_STRING) + // Step 1: Query CONSUL to get the IP/PORT of CONFIG BINDING SERVICE + .flatMap(fetchUrlContentFunction) + // Step 2: Fetch the generated configurations from CONFIG BINDING SERVICE + .flatMap(ConfigBindingServiceJsonSupplier::parseConsulConfigBindingServiceQueryResponseJson) + // Step 3: create url from service address and service port + .flatMap(ConfigBindingServiceJsonSupplier::createConfigServiceURL) + // Step 4: Fetch final config binding service generated application configuration json string + .flatMap(fetchUrlContentFunction); + } + + /** + * Creates URL using config binding service ip address and port + * + * @param consulConfigBindingServiceQueryResponse consul config binding service query response containing config + * binding service address and service port + * + * @return config service url to fetch service configuration + */ + private static Optional<String> createConfigServiceURL(final ConsulConfigBindingServiceQueryResponse + consulConfigBindingServiceQueryResponse) { + final String configBindingServiceAddress = consulConfigBindingServiceQueryResponse.getServiceAddress(); + final Integer configServicePort = consulConfigBindingServiceQueryResponse.getServicePort(); + + if (configBindingServiceAddress == null && configServicePort == null) { + logger.error("Config Binding Service Address & Port are not present."); + return Optional.empty(); + } + + return Optional.of(String.format(ConfigBindingServiceConstants.CONFIG_SERVICE_QUERY_URL_STRING, + configBindingServiceAddress, configServicePort, + ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE)); + + } + + private static Optional<ConsulConfigBindingServiceQueryResponse> + parseConsulConfigBindingServiceQueryResponseJson(final String configBindingServiceQueryResponseJson) { + // parse json + final Optional<List<ConsulConfigBindingServiceQueryResponse>> configBindingServiceQueryResponseOptional = + AnalyticsModelJsonConversion.CONFIG_BINDING_SERVICE_LIST_JSON_FUNCTION + .apply(configBindingServiceQueryResponseJson); + + // check parsing is successful and at least 1 config binding query response is present + if (!configBindingServiceQueryResponseOptional.isPresent() || + configBindingServiceQueryResponseOptional.get().isEmpty()) { + logger.error("No Consul config binding service information found in JSON: {} ", + configBindingServiceQueryResponseJson); + return Optional.empty(); + } + + // return first consul query response + return Optional.of(configBindingServiceQueryResponseOptional.get().get(0)); + } + + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplier.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplier.java new file mode 100644 index 0000000..6837a55 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/CreationTimestampSupplier.java @@ -0,0 +1,49 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.supplier; + +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.function.Supplier; + +import org.onap.dcae.analytics.model.AnalyticsModelConstants; + +/** + * Provides current date/time in UTC formatted string + * + * @author Rajiv Singla + */ +public class CreationTimestampSupplier implements Supplier<String> { + + private static final DateTimeFormatter DATE_TIME_FORMATTER = + DateTimeFormatter.ofPattern(AnalyticsModelConstants.ANALYTICS_DATE_FORMAT); + + @Override + public String get() { + return DATE_TIME_FORMATTER.format(ZonedDateTime.now(ZoneOffset.UTC)); + } + + + public static Date getParsedDate(final String dateString) { + return Date.from(ZonedDateTime.parse(dateString, DATE_TIME_FORMATTER).toInstant()); + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplier.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplier.java new file mode 100644 index 0000000..e1ec86a --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/RandomIdSupplier.java @@ -0,0 +1,55 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.supplier; + +import java.util.Locale; +import java.util.Random; +import java.util.function.Supplier; + +/** + * Supplies unsecured random ID with upper case with desired maximum length. + * + * @author Rajiv Singla + */ +public class RandomIdSupplier implements Supplier<String> { + + private static final char[] LETTERS = + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); + private static final Random RANDOM = new Random(); + + private final int maxLength; + + public RandomIdSupplier(int maxLength) { + this.maxLength = maxLength; + } + + + @Override + public String get() { + + final StringBuilder sb = new StringBuilder(maxLength); + for (int i = 0; i < maxLength; i++) { + sb.append(LETTERS[RANDOM.nextInt(LETTERS.length)]); + } + + return sb.toString().toUpperCase(Locale.getDefault()); + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplier.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplier.java new file mode 100644 index 0000000..21c04c2 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/util/supplier/UnboundedSupplier.java @@ -0,0 +1,92 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.supplier; + + +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; + +/** + * An unbounded supplier that can be used to generated unbounded sequence of elements + * in random or round robin generation mode. + * + * @param <T> The type of result supplied by the supplier + * + * @author Rajiv Singla + */ +public class UnboundedSupplier<T> implements Supplier<T> { + + private final T[] elements; + private final GenerationMode generationMode; + private final int numElements; + private AtomicInteger index; + private Random random; + + /** + * Sequence Generation Mode + */ + public enum GenerationMode { + /** + * Sequence will be generated in uniformly distributed random + */ + RANDOM, + /** + * Sequence will be generated in round robin manner + */ + ROUND_ROBIN; + } + + @SafeVarargs + public UnboundedSupplier(final GenerationMode generationMode, final T... elements) { + if (elements == null || elements.length < 1) { + throw new IllegalArgumentException("Element size must be greater than 1"); + } + this.generationMode = generationMode; + this.elements = elements; + numElements = elements.length; + if (numElements > 1) { + if (generationMode == GenerationMode.ROUND_ROBIN) { + index = new AtomicInteger(-1); + } else { + random = new Random(); + } + } + } + + @SafeVarargs + public UnboundedSupplier(T... elements) { + this(GenerationMode.ROUND_ROBIN, elements); + } + + @Override + public T get() { + if (numElements == 1) { + return elements[0]; + } + if (generationMode == GenerationMode.ROUND_ROBIN) { + index.getAndUpdate(idx -> idx >= numElements - 1 ? 0 : idx + 1); + return elements[index.get()]; + } else { + return elements[random.nextInt(numElements)]; + } + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/BaseAnalyticsModelTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/BaseAnalyticsModelTest.java new file mode 100644 index 0000000..ec0f329 --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/BaseAnalyticsModelTest.java @@ -0,0 +1,31 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model; + +import org.onap.dcae.analytics.test.BaseAnalyticsUnitTest; + +/** + * Base Analytics Model Unit Test. + * + * @author Rajiv Singla + */ +public abstract class BaseAnalyticsModelTest extends BaseAnalyticsUnitTest { + +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java new file mode 100644 index 0000000..d3368de --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/AlertTypeMixinTest.java @@ -0,0 +1,54 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.model.BaseAnalyticsModelTest; +import org.onap.dcae.analytics.model.cef.AlertType; + + +/** + * Test Alert Type Mixin JSON conversions. + * + * @author Rajiv Singla + */ +class AlertTypeMixinTest extends BaseAnalyticsModelTest { + + // NOTE: Alert type enum has some special customizations in AlertTypeMixin class + // as Java enum names does not allow for "-" so actual values are coded as enum names + @Test + @DisplayName("Test Alert Type Json Conversions") + public void testAlertTypeJsonConversions() throws Exception { + + final String alertTypeJson = serializeModelToJson(AlertType.CARD_ANOMALY, ANALYTICS_MODEL_OBJECT_MAPPER); + Assertions.assertThat(alertTypeJson) + .as("Alert Type Json for CARD ANOMALY must have hyphen in it").isEqualTo("\"CARD-ANOMALY\""); + // convert parsed alert type back to enum + final AlertType alertType = ANALYTICS_MODEL_OBJECT_MAPPER.readValue(alertTypeJson, AlertType.class); + Assertions.assertThat(alertType) + .as("Json String for CARD ANOMALY with hyphen can be converted back to Alert Type") + .isEqualTo(AlertType.CARD_ANOMALY); + } + +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventListenerMixinTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventListenerMixinTest.java new file mode 100644 index 0000000..2e606cb --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/cef/EventListenerMixinTest.java @@ -0,0 +1,81 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.cef; + +import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER; +import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.EVENT_LISTENER_JSON_FUNCTION; +import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.EVENT_LISTENER_LIST_JSON_FUNCTION; + +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.model.BaseAnalyticsModelTest; +import org.onap.dcae.analytics.model.cef.EventListener; +import org.onap.dcae.analytics.model.cef.Field; +import org.onap.dcae.analytics.model.cef.NamedArrayOfFields; + +/** + * Contains test for CEF Event Listener JSON Conversions. + * + * @author Rajiv Singla + */ +class EventListenerMixinTest extends BaseAnalyticsModelTest { + + @Test + @DisplayName("Test single CEF JSON conversions") + void testSingleEventListenerJsonConversion() { + + final EventListener eventListener = assertJsonConversions(TestFileLocation.CEF_JSON_MESSAGE, + EVENT_LISTENER_JSON_FUNCTION, ANALYTICS_MODEL_OBJECT_MAPPER); + + Assertions.assertThat(eventListener).isNotNull(); + Assertions.assertThat(eventListener.getEvent()).isNotNull(); + final List<Field> additionalFields = + eventListener.getEvent().getMeasurementsForVfScalingFields().getAdditionalFields(); + + Assertions.assertThat(additionalFields.size()).as("Additional Fields size is 2").isEqualTo(2); + + final List<NamedArrayOfFields> additionalMeasurements = + eventListener.getEvent().getMeasurementsForVfScalingFields().getAdditionalMeasurements(); + + Assertions.assertThat(additionalMeasurements.size()).as("Additional Measurements size must be 1").isEqualTo(1); + + final List<Field> arrayOfFields = additionalMeasurements.get(0).getArrayOfFields(); + + Assertions.assertThat(arrayOfFields.size()).as("Array Of Field size must be 6").isEqualTo(6); + } + + @Test + @DisplayName("Test collection of CEF JSON messages conversions") + void testCollectionOfEventListenersJsonConversion() { + + List<EventListener> eventListeners = + assertJsonConversions(TestFileLocation.CEF_JSON_MESSAGES, + EVENT_LISTENER_LIST_JSON_FUNCTION, ANALYTICS_MODEL_OBJECT_MAPPER); + Assertions.assertThat(eventListeners).isNotNull(); + Assertions.assertThat(eventListeners.size()).as("Event Listeners size must be 31").isEqualTo(31); + + // Checks serialization + testSerialization(eventListeners, getClass()); + + } +} diff --git a/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/configbindingservice/ConsulConfigBindingServiceQueryResponseMixinTest.java b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/configbindingservice/ConsulConfigBindingServiceQueryResponseMixinTest.java new file mode 100644 index 0000000..b1b9fae --- /dev/null +++ b/dcae-analytics/dcae-analytics-model/src/test/java/org/onap/dcae/analytics/model/util/json/mixin/configbindingservice/ConsulConfigBindingServiceQueryResponseMixinTest.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.model.util.json.mixin.configbindingservice; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER; +import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion + .CONFIG_BINDING_SERVICE_LIST_JSON_FUNCTION; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.model.BaseAnalyticsModelTest; +import org.onap.dcae.analytics.model.configbindingservice.ConsulConfigBindingServiceQueryResponse; + +/** + * Consul Config Binding Service Query Response Mixin Test. + * + * @author Rajiv Singla + */ +class ConsulConfigBindingServiceQueryResponseMixinTest extends BaseAnalyticsModelTest { + + + @Test + @DisplayName("Test Config Service Bindings JSON conversions") + void testConfigServiceBindingsConversions() throws Exception { + + List<ConsulConfigBindingServiceQueryResponse> configServiceBindings = + assertJsonConversions(TestFileLocation.CONFIG_SERVICE_BINDINGS_JSON, + CONFIG_BINDING_SERVICE_LIST_JSON_FUNCTION, ANALYTICS_MODEL_OBJECT_MAPPER); + + assertThat(configServiceBindings).isNotNull(); + assertThat(configServiceBindings.size()).as("There should be only 1 binding config").isEqualTo(1); + + final ConsulConfigBindingServiceQueryResponse configBindingServiceQueryResponse = configServiceBindings.get(0); + assertThat(configBindingServiceQueryResponse.getAddress()) + .as("Config Service Binding ServiceAddress must be 135.25.108.161").isEqualTo("135.25.108.161"); + assertThat(configBindingServiceQueryResponse.getServicePort()) + .as("Config Service Binding ServicePort must be 32769").isEqualTo(32769); + assertThat(configBindingServiceQueryResponse.getDynamicProperties()) + .as("Dynamic Properties must be empty if all bindings are successful").isEmpty(); + } + +} |