58d8a4cd550792b8f9e697156707e386663cd76c
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / inventory / create / CreateInventoryService.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.inventory.create;
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 CreateInventoryService {
42
43         private static final Logger logger = LoggerFactory.getLogger(CreateInventoryService.class);
44
45         @Autowired
46         public Environment env;
47
48         @Autowired
49         private CreateInventoryTask createInventory;
50
51         @PostConstruct
52         public void auditAAIInventory() {
53                 String auth = "";
54                 try {
55                         auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
56                 } catch (IllegalStateException | GeneralSecurityException e) {
57                         logger.error("Error Decrypting Password", e);
58                 }
59                 ClientRequestInterceptor interceptor = new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"),
60                                 auth);
61                 ExternalTaskClient client = ExternalTaskClient.create()
62                                 .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor)
63                                 .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
64                 client.subscribe("InventoryCreate").lockDuration(60000)
65                                 .handler(createInventory::executeExternalTask).open();
66         }
67
68 }