2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.sdnc.dg.loader;
28 import java.util.ArrayList;
29 import java.util.List;
31 import org.apache.commons.io.FileUtils;
32 import org.apache.commons.lang.StringUtils;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
41 public class DGXMLActivate {
43 private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
44 private final SvcLogicStore store;
45 public static String STRING_ENCODING = "utf-8";
47 public DGXMLActivate(String propfile) throws Exception{
48 if(StringUtils.isBlank(propfile)){
49 throw new Exception(propfile + " Profile file is not defined");
51 this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
54 protected DGXMLActivate(SvcLogicStore store) {
59 public void activateDg(String activateFilePath) throws Exception {
60 logger.info("******************** Activating DG into Database *****************************");
62 List<String> errors = new ArrayList<String>();
63 if(this.store != null){
64 File activateFile = new File(activateFilePath);
65 if(activateFile != null && activateFile.isFile()){
66 List<String> fileLines = FileUtils.readLines(activateFile,STRING_ENCODING);
67 if(fileLines != null ){
68 for (String line : fileLines) {
69 if(line != null && ! line.trim().startsWith("#")){
70 String lineArray[] = line.trim().split(":");
72 if(lineArray != null && lineArray.length >= 4){
73 String module = lineArray[0];
74 String rpc = lineArray[1];
75 String version = lineArray[2];
76 String mode = lineArray[3];
77 if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc)
78 && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){
79 logger.info("Activating DG :" + line);
80 SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode);
82 logger.info("Found Graph :" + line + " Activating ...");
83 this.store.activate(graph);
85 throw new Exception("Failed to fetch from Database");
89 } catch (Exception e) {
91 errors.add("Failed to Activate "+line + ", "+e.getMessage());
97 throw new Exception(activateFile + " is not a valid Activate file Path");
100 throw new Exception("Failed to initialise SvcLogicStore");
103 if(errors.size() > 0){
104 throw new Exception(errors.toString());
106 } catch (Exception e) {
107 logger.error(e.getMessage());
112 public static void main(String[] args) {
114 String activateFile = null;
115 String propertyPath = null;
117 if(args != null && args.length >= 2){
118 activateFile = args[0];
119 propertyPath = args[1];
121 throw new Exception("Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
124 DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath);
125 dgXmlActivate.activateDg(activateFile);
126 } catch (Exception e) {