From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../org/onap/sdnc/dg/loader/DGXMLActivate.java | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java (limited to 'appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java') diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java new file mode 100644 index 000000000..6af447742 --- /dev/null +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.dg.loader; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; +import org.onap.ccsdk.sli.core.sli.SvcLogicStore; +import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +public class DGXMLActivate { + + private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); + private final SvcLogicStore store; + public static String STRING_ENCODING = "utf-8"; + + public DGXMLActivate(String propfile) throws Exception{ + if(StringUtils.isBlank(propfile)){ + throw new Exception(propfile + " Profile file is not defined"); + } + this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); + } + + protected DGXMLActivate(SvcLogicStore store) { + this.store = store; + } + + + public void activateDg(String activateFilePath) throws Exception { + logger.info("******************** Activating DG into Database *****************************"); + try { + List errors = new ArrayList(); + if(this.store != null){ + File activateFile = new File(activateFilePath); + if(activateFile != null && activateFile.isFile()){ + List fileLines = FileUtils.readLines(activateFile,STRING_ENCODING); + if(fileLines != null ){ + for (String line : fileLines) { + if(line != null && ! line.trim().startsWith("#")){ + String lineArray[] = line.trim().split(":"); + try { + if(lineArray != null && lineArray.length >= 4){ + String module = lineArray[0]; + String rpc = lineArray[1]; + String version = lineArray[2]; + String mode = lineArray[3]; + if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc) + && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){ + logger.info("Activating DG :" + line); + SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode); + if(graph != null){ + logger.info("Found Graph :" + line + " Activating ..."); + this.store.activate(graph); + }else{ + throw new Exception("Failed to fetch from Database"); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + errors.add("Failed to Activate "+line + ", "+e.getMessage()); + } + } + } + } + }else{ + throw new Exception(activateFile + " is not a valid Activate file Path"); + } + }else{ + throw new Exception("Failed to initialise SvcLogicStore"); + } + + if(errors.size() > 0){ + throw new Exception(errors.toString()); + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + + + public static void main(String[] args) { + try { + String activateFile = null; + String propertyPath = null; + + if(args != null && args.length >= 2){ + activateFile = args[0]; + propertyPath = args[1]; + }else{ + throw new Exception("Sufficient inputs for DGXMLActivate are missing "); + } + + DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath); + dgXmlActivate.activateDg(activateFile); + } catch (Exception e) { + e.printStackTrace(); + }finally { + System.exit(1); + } + } + +} -- cgit 1.2.3-korg