6ea14dcac7f6ab219ae88f2b7b27425cdba83cbd
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / audit / AuditStackService.java
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 package org.onap.so.adapters.audit;
22
23 import java.security.GeneralSecurityException;
24
25 import javax.annotation.PostConstruct;
26
27 import org.camunda.bpm.client.ExternalTaskClient;
28 import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
29 import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
30 import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
31 import org.onap.so.utils.CryptoUtils;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.Profile;
36 import org.springframework.core.env.Environment;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 @Profile("!test")
41 public class AuditStackService {
42
43         private static final Logger logger = LoggerFactory.getLogger(AuditStackService.class);
44
45         @Autowired
46         public Environment env;
47
48         @Autowired
49         private AuditCreateStackService auditCreateStack;
50         
51         @Autowired
52         private AuditDeleteStackService auditDeleteStack;
53
54         @PostConstruct
55         public void auditAddAAIInventory() {
56                 String auth = "";
57                 try {
58                         auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
59                 } catch (IllegalStateException | GeneralSecurityException e) {
60                         logger.error("Error Decrypting Password", e);
61                 }
62                 ClientRequestInterceptor interceptor = new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"),
63                                 auth);
64                 ExternalTaskClient client = ExternalTaskClient.create()
65                                 .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor)
66                                 .asyncResponseTimeout(120000).build();
67                 client.subscribe("InventoryAddAudit").lockDuration(60000)
68                                 .handler(auditCreateStack::executeExternalTask).open();
69         }
70         
71         @PostConstruct
72         public void auditDeleteAAIInventory() {
73                 String auth = "";
74                 try {
75                         auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
76                 } catch (IllegalStateException | GeneralSecurityException e) {
77                         logger.error("Error Decrypting Password", e);
78                 }
79                 ClientRequestInterceptor interceptor = new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"),
80                                 auth);
81                 ExternalTaskClient client = ExternalTaskClient.create()
82                                 .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor)
83                                 .asyncResponseTimeout(120000).build();
84                 client.subscribe("InventoryDeleteAudit").lockDuration(60000)
85                                 .handler(auditDeleteStack::executeExternalTask).open();
86         }
87
88 }