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.onap.sdnc.dg.loader;
28 import java.util.ArrayList;
29 import java.util.List;
30 import org.apache.commons.io.FileUtils;
31 import org.apache.commons.lang.StringUtils;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
40 public class DGXMLActivate {
42 private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
43 private final SvcLogicStore store;
44 public static String STRING_ENCODING = "utf-8";
46 public DGXMLActivate(String propfile) throws Exception {
47 if (StringUtils.isBlank(propfile)) {
48 throw new Exception(propfile + " Profile file is not defined");
50 this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
53 protected DGXMLActivate(SvcLogicStore store) {
58 public void activateDg(String activateFilePath) throws Exception {
60 "******************** 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.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)
78 && StringUtils.isNotBlank(rpc)
79 && StringUtils.isNotBlank(version)
80 && StringUtils.isNotBlank(mode)) {
81 logger.info("Activating DG :" + line);
83 this.store.fetch(module, rpc, version, mode);
86 "Found Graph :" + line + " Activating ...");
87 this.store.activate(graph);
90 "Failed to fetch from Database");
94 } catch (Exception e) {
97 "Failed to Activate " + line + ", " + e.getMessage());
103 throw new Exception(activateFile + " is not a valid Activate file Path");
106 throw new Exception("Failed to initialise SvcLogicStore");
109 if (errors.size() > 0) {
110 throw new Exception(errors.toString());
112 } catch (Exception e) {
113 logger.error(e.getMessage());
118 public static void main(String[] args) {
120 String activateFile = null;
121 String propertyPath = null;
123 if (args != null && args.length >= 2) {
124 activateFile = args[0];
125 propertyPath = args[1];
128 "Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
131 DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath);
132 dgXmlActivate.activateDg(activateFile);
133 } catch (Exception e) {