Implement interface to SDC for ActivitySpec
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / activity / DeployActivitySpecs.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.asdc.activity;
22
23 import javax.annotation.PostConstruct;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.core.env.Environment;
28 import org.springframework.stereotype.Component;
29 import org.onap.so.asdc.activity.beans.ActivitySpec;
30 import org.onap.so.db.catalog.client.CatalogDbClient;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 @Component
35 public class DeployActivitySpecs {
36     @Autowired
37     private ActivitySpecsActions activitySpecsActions;
38
39     @Autowired
40     private Environment env;
41
42     private static final String SDC_ENDPOINT = "mso.asdc.config.activity.endpoint";
43
44     protected static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class);
45
46     public void deployActivities() throws Exception {
47         String hostname = this.env.getProperty(SDC_ENDPOINT);
48         List<ActivitySpec> activitySpecs = new ArrayList<ActivitySpec>();
49
50         // Initialize activitySpecs from Catalog DB
51
52         for (ActivitySpec activitySpec : activitySpecs) {
53             String activitySpecId = activitySpecsActions.createActivitySpec(hostname, activitySpec);
54             if (activitySpecId != null) {
55                 logger.info("{} {}", "Successfully created activitySpec", activitySpec.getName());
56                 boolean certificationResult = activitySpecsActions.certifyActivitySpec(hostname, activitySpecId);
57                 if (certificationResult) {
58                     logger.info("{} {}", "Successfully certified activitySpec", activitySpec.getName());
59                 } else {
60                     logger.info("{} {}", "Failed to certify activitySpec", activitySpec.getName());
61                 }
62             } else {
63                 logger.info("{} {}", "Failed to create activitySpec", activitySpec.getName());
64             }
65         }
66     }
67 }