summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
authorShiwei Tian <tian.shiwei@zte.com.cn>2017-09-25 10:50:01 +0800
committerShiwei Tian <tian.shiwei@zte.com.cn>2017-09-25 10:50:01 +0800
commit35ca27d9ac88a344fdc6b24838281d75c5445b1f (patch)
tree496ba1f56a6f94e50a8135aafe4cc2ef1bbfef77 /holmes-actions
parent4d3a7fb81c7adc956c56a9003b195a34ef1dcd59 (diff)
add correlation analysis
Issue-ID: HOLMES-44 Change-Id: I357587ff182c3bc900f3a03ca3a28a7d73d9564a Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java
new file mode 100644
index 0000000..d0a4160
--- /dev/null
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.onap.holmes.common.aai;
+
+import java.util.List;
+import java.util.Optional;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
+import org.onap.holmes.common.aai.entity.VmEntity;
+import org.onap.holmes.common.exception.CorrelationException;
+
+@Slf4j
+public class CorrelationUtil {
+
+ private AaiQuery aaiQuery;
+
+ private static class LazyHolder {
+ private static final CorrelationUtil INSTANCE = new CorrelationUtil();
+ }
+ private CorrelationUtil (){}
+
+ public static final CorrelationUtil getInstance() {
+ return LazyHolder.INSTANCE;
+ }
+
+ public boolean isTopologicallyRelated(String childId, String rootId) {
+
+ return Optional.ofNullable(getVmEntity(rootId)).map(vmEntity ->
+ getIsRelated(childId, vmEntity)).orElse(false);
+ }
+
+ private boolean getIsRelated(String childId, VmEntity vmEntity) {
+ List<Relationship> relationships = vmEntity.getRelationshipList().getRelationships();
+ for (Relationship relationship : relationships) {
+ boolean isRelated = relationship.getRelationshipDataList().stream().anyMatch(
+ relationshipData -> relationshipData.getRelationshipValue().equals(childId));
+ if (isRelated) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private VmEntity getVmEntity(String rootId) {
+ VmEntity vmEntity = null;
+ try {
+ vmEntity = aaiQuery.getAaiVmData("", rootId);
+ } catch (CorrelationException e) {
+ log.error("Failed to get vm data", e.getMessage());
+ }
+ return vmEntity;
+ }
+}