diff options
Diffstat (limited to 'appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java')
-rw-r--r-- | appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java | 256 |
1 files changed, 128 insertions, 128 deletions
diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java index 1373143cf..f5eb2441f 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLLoadNActivate.java @@ -36,133 +36,133 @@ import org.openecomp.sdnc.sli.SvcLogicStore; import org.openecomp.sdnc.sli.SvcLogicStoreFactory; public class DGXMLLoadNActivate { - private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); - private final SvcLogicStore store; - public static String STRING_ENCODING = "utf-8"; - - public DGXMLLoadNActivate(String propfile) throws Exception{ - if(StringUtils.isBlank(propfile)){ - throw new Exception(propfile + " Profile file is not defined"); - } - this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); - } - - public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException{ - if(dgXMLpath != null ){ - SvcLogicParser.load(dgXMLpath, this.store); - } - } - - private void loadDGXMLDir(String xmlPath) throws Exception { - try { - logger.info("******************** Loading DG into Database *****************************"); - List<String> errors = new ArrayList<String>(); - if(this.store != null){ - File xmlDir = new File(xmlPath); - if(xmlDir != null && xmlDir.isDirectory()){ - String[] extensions = new String[] { "xml", "XML" }; - List<File> files = (List<File>) FileUtils.listFiles(xmlDir, extensions, true); - for (File file : files) { - logger.info("Loading DG XML file :" + file.getCanonicalPath()); - try{ - SvcLogicParser.load(file.getCanonicalPath(), this.store); - }catch (Exception e) { - errors.add("Failed to load XML "+file.getCanonicalPath() + ", Exception : "+e.getMessage()); - } - } - }else{ - throw new Exception(xmlPath + " is not a valid XML Directory"); - } - }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 void activateDg(String activateFilePath) throws Exception { - logger.info("******************** Activating DG into Database *****************************"); - try { - List<String> errors = new ArrayList<String>(); - if(this.store != null){ - File activateFile = new File(activateFilePath); - if(activateFile != null && activateFile.isFile()){ - List<String> 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 xmlPath = null; - String propertyPath = null; - String activateFile = null; - - if(args != null && args.length >= 3){ - xmlPath = args[0]; - activateFile = args[1]; - propertyPath = args[2]; - }else{ - throw new Exception("Sufficient inputs for DGXMLLoadNActivate are missing <xmlpath> <activatefile> <dbPropertyfile>"); - } - - //propertyPath = "/Users/bs2796/0Source/ecomp/bvc-3.2.2/others/properties/dblib.properties"; - //xmlPath = DGXMLLoadNActivate.class.getClassLoader().getResource(".").getPath() +"/xml" ; - - DGXMLLoadNActivate dgXMLLoadDB = new DGXMLLoadNActivate(propertyPath); - dgXMLLoadDB.loadDGXMLDir(xmlPath); - dgXMLLoadDB.activateDg(activateFile); - } catch (Exception e) { - e.printStackTrace(); - }finally { - System.exit(1); - } - } + private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class); + private final SvcLogicStore store; + public static String STRING_ENCODING = "utf-8"; + + public DGXMLLoadNActivate(String propfile) throws Exception{ + if(StringUtils.isBlank(propfile)){ + throw new Exception(propfile + " Profile file is not defined"); + } + this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); + } + + public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException{ + if(dgXMLpath != null ){ + SvcLogicParser.load(dgXMLpath, this.store); + } + } + + private void loadDGXMLDir(String xmlPath) throws Exception { + try { + logger.info("******************** Loading DG into Database *****************************"); + List<String> errors = new ArrayList<String>(); + if(this.store != null){ + File xmlDir = new File(xmlPath); + if(xmlDir != null && xmlDir.isDirectory()){ + String[] extensions = new String[] { "xml", "XML" }; + List<File> files = (List<File>) FileUtils.listFiles(xmlDir, extensions, true); + for (File file : files) { + logger.info("Loading DG XML file :" + file.getCanonicalPath()); + try{ + SvcLogicParser.load(file.getCanonicalPath(), this.store); + }catch (Exception e) { + errors.add("Failed to load XML "+file.getCanonicalPath() + ", Exception : "+e.getMessage()); + } + } + }else{ + throw new Exception(xmlPath + " is not a valid XML Directory"); + } + }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 void activateDg(String activateFilePath) throws Exception { + logger.info("******************** Activating DG into Database *****************************"); + try { + List<String> errors = new ArrayList<String>(); + if(this.store != null){ + File activateFile = new File(activateFilePath); + if(activateFile != null && activateFile.isFile()){ + List<String> 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 xmlPath = null; + String propertyPath = null; + String activateFile = null; + + if(args != null && args.length >= 3){ + xmlPath = args[0]; + activateFile = args[1]; + propertyPath = args[2]; + }else{ + throw new Exception("Sufficient inputs for DGXMLLoadNActivate are missing <xmlpath> <activatefile> <dbPropertyfile>"); + } + + //propertyPath = "/Users/bs2796/0Source/ecomp/bvc-3.2.2/others/properties/dblib.properties"; + //xmlPath = DGXMLLoadNActivate.class.getClassLoader().getResource(".").getPath() +"/xml" ; + + DGXMLLoadNActivate dgXMLLoadDB = new DGXMLLoadNActivate(propertyPath); + dgXMLLoadDB.loadDGXMLDir(xmlPath); + dgXMLLoadDB.activateDg(activateFile); + } catch (Exception e) { + e.printStackTrace(); + }finally { + System.exit(1); + } + } } |