2 * ============LICENSE_START=======================================================
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
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.openecomp.sdnc.dg.loader;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.apache.commons.io.FileUtils;
28 import org.apache.commons.lang.StringUtils;
29 import org.openecomp.sdnc.sli.SvcLogicGraph;
30 import org.openecomp.sdnc.sli.SvcLogicStore;
31 import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
37 public class DGXMLActivate {
39 private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
40 private final SvcLogicStore store;
41 public static String STRING_ENCODING = "utf-8";
43 public DGXMLActivate(String propfile) throws Exception{
44 if(StringUtils.isBlank(propfile)){
45 throw new Exception(propfile + " Profile file is not defined");
47 this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
51 public void activateDg(String activateFilePath) throws Exception {
52 logger.info("******************** Activating DG into Database *****************************");
54 List<String> errors = new ArrayList<String>();
55 if(this.store != null){
56 File activateFile = new File(activateFilePath);
57 if(activateFile != null && activateFile.isFile()){
58 List<String> fileLines = FileUtils.readLines(activateFile,STRING_ENCODING);
59 if(fileLines != null ){
60 for (String line : fileLines) {
61 if(line != null && ! line.trim().startsWith("#")){
62 String lineArray[] = line.trim().split(":");
64 if(lineArray != null && lineArray.length >= 4){
65 String module = lineArray[0];
66 String rpc = lineArray[1];
67 String version = lineArray[2];
68 String mode = lineArray[3];
69 if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc)
70 && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){
71 logger.info("Activating DG :" + line);
72 SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode);
74 logger.info("Found Graph :" + line + " Activating ...");
75 this.store.activate(graph);
77 throw new Exception("Failed to fetch from Database");
81 } catch (Exception e) {
83 errors.add("Failed to Activate "+line + ", "+e.getMessage());
89 throw new Exception(activateFile + " is not a valid Activate file Path");
92 throw new Exception("Failed to initialise SvcLogicStore");
95 if(errors.size() > 0){
96 throw new Exception(errors.toString());
98 } catch (Exception e) {
99 logger.error(e.getMessage());
104 public static void main(String[] args) {
106 String activateFile = null;
107 String propertyPath = null;
109 if(args != null && args.length >= 2){
110 activateFile = args[0];
111 propertyPath = args[1];
113 throw new Exception("Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
116 DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath);
117 dgXmlActivate.activateDg(activateFile);
118 } catch (Exception e) {