2f7155bffc7fa842f0e6e28a448965f98e7b5af1
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21
22 package org.onap.so.adapters.tasks.audit;
23
24 import java.util.Optional;
25 import org.onap.so.objects.audit.AAIObjectAudit;
26 import org.onap.so.objects.audit.AAIObjectAuditList;
27 import org.onap.so.utils.ExternalTaskUtils;
28 import org.onap.so.utils.RetrySequenceLevel;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.core.env.Environment;
33 import org.springframework.stereotype.Component;
34
35 @Component
36 public abstract class AbstractAuditService extends ExternalTaskUtils {
37
38     private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
39
40
41
42     protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI =
43             "Unable to find all VServers and L-Interaces in A&AI";
44
45     protected static final String UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK = "Unable to find VServers in Openstack";
46
47     @Autowired
48     public Environment env;
49
50     public AbstractAuditService() {
51         super(RetrySequenceLevel.LONG);
52     }
53
54     /**
55      * @param auditHeatStackFailed
56      * @param auditList
57      * @return
58      */
59     protected boolean didCreateAuditFail(Optional<AAIObjectAuditList> auditList) {
60         if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) {
61             if (logger.isInfoEnabled()) {
62                 logger.info("Audit Results: {}", auditList.get().toString());
63             }
64             return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist())
65                     .findFirst().map(v -> true).orElse(false);
66         } else {
67             return false;
68         }
69     }
70
71     /**
72      * @param auditHeatStackFailed
73      * @param auditList
74      * @return
75      */
76     protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) {
77         if (auditList.getAuditList() != null && !auditList.getAuditList().isEmpty()) {
78             if (logger.isInfoEnabled()) {
79                 logger.info("Audit Results: {}", auditList.toString());
80             }
81             return auditList.getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
82                     .map(v -> true).orElse(false);
83         } else {
84             return false;
85         }
86     }
87 }