2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.audit;
23 import java.security.GeneralSecurityException;
24 import javax.annotation.PostConstruct;
25 import org.camunda.bpm.client.ExternalTaskClient;
26 import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
27 import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
28 import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
29 import org.onap.so.utils.CryptoUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.Profile;
34 import org.springframework.core.env.Environment;
35 import org.springframework.stereotype.Component;
39 public class AuditStackService {
41 private static final Logger logger = LoggerFactory.getLogger(AuditStackService.class);
43 private static final String DEFAULT_AUDIT_LOCK_TIME = "60000";
45 private static final String DEFAULT_MAX_CLIENTS_FOR_TOPIC = "10";
48 public Environment env;
51 private AuditCreateStackService auditCreateStack;
54 private AuditDeleteStackService auditDeleteStack;
57 private AuditQueryStackService auditQueryStack;
60 public void auditAddAAIInventory() {
61 for (int i = 0; i < getMaxClients(); i++) {
62 ExternalTaskClient client = createExternalTaskClient();
63 client.subscribe("InventoryAddAudit")
64 .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
65 .handler(auditCreateStack::executeExternalTask).open();
70 public void auditDeleteAAIInventory() {
71 for (int i = 0; i < getMaxClients(); i++) {
72 ExternalTaskClient client = createExternalTaskClient();
73 client.subscribe("InventoryDeleteAudit")
74 .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
75 .handler(auditDeleteStack::executeExternalTask).open();
80 public void auditQueryInventory() {
81 for (int i = 0; i < getMaxClients(); i++) {
82 ExternalTaskClient client = createExternalTaskClient();
83 client.subscribe("InventoryQueryAudit")
84 .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
85 .handler(auditQueryStack::executeExternalTask).open();
89 protected ExternalTaskClient createExternalTaskClient() {
90 ClientRequestInterceptor interceptor = createClientRequestInterceptor();
91 return ExternalTaskClient.create().baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1)
92 .addInterceptor(interceptor).asyncResponseTimeout(120000)
93 .backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
96 protected ClientRequestInterceptor createClientRequestInterceptor() {
99 auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
100 } catch (IllegalStateException | GeneralSecurityException e) {
101 logger.error("Error Decrypting Password", e);
103 return new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
106 protected int getMaxClients() {
107 return Integer.parseInt(env.getProperty("workflow.topics.maxClients", DEFAULT_MAX_CLIENTS_FOR_TOPIC));