/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ package com.pcbsys.nirvana.nAdminAPI.apps; import com.pcbsys.foundation.utils.fEnvironment; import com.pcbsys.nirvana.client.nSessionAttributes; import com.pcbsys.nirvana.client.nSessionFactory; import com.pcbsys.nirvana.nAdminAPI.xml.tools.ImportExportManager; import com.pcbsys.nirvana.nAdminAPI.xml.tools.ImportExportParametersBuilder; import com.pcbsys.nirvana.nAdminAPI.nRealmNode; import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaRealm; import com.pcbsys.nirvana.nAdminAPI.xml.NirvanaRealmParser; import java.io.File; import java.util.Date; /** * This application can be used to import the objects into a realm. *

* The program will import realm acl entries and permissions, and configurations * for all channels, queues, interfaces and schedulers. */ public class nImportRealmXML { private String realmUrl = null; private String fileName = null; private ImportExportParametersBuilder importParameters = null; /** * Constructor for the class, takes the string realm url */ private nImportRealmXML(String[] args) { nRealmNode node = null; try { processArgs(args); report("Connecting to " + realmUrl); // construct the session attributes for the realm nSessionAttributes attr = new nSessionAttributes(realmUrl); // construct the realm node node = new nRealmNode(attr); node.waitForEntireNameSpace(5000); // construct the importer NirvanaRealm realm = NirvanaRealmParser.getNirvanaRealm(fileName); ImportExportManager.importConfiguration(node, realm, importParameters); } catch (Exception ex) { ex.printStackTrace(); } finally { if (node != null) { node.close(); nSessionFactory.shutdown(); } } } /** * Main program thread, takes a realm URL as the parameter to start the search */ public static void main(String[] args) { //Process Environment Variables processEnvironmentVariable("RNAME"); processEnvironmentVariable("LOGLEVEL"); processEnvironmentVariable("HPROXY"); processEnvironmentVariable("HAUTH"); processEnvironmentVariable("CKEYSTORE"); processEnvironmentVariable("CKEYSTOREPASSWD"); processEnvironmentVariable("CAKEYSTORE"); processEnvironmentVariable("CAKEYSTOREPASSWD"); // Install any proxy server settings fEnvironment.setProxyEnvironments(); // Install JSSE SSL Environement settings fEnvironment.setSSLEnvironments(); new nImportRealmXML(args); } private void processArgs(String[] args) { switch (args.length) { case 0: Usage(); UsageEnv(); System.exit(1); case 1: if (args[0].equals("-?")) { UsageEnv(); } System.setProperty("FILE", args[0]); getOptions(null); break; default: System.setProperty("FILE", args[0]); getOptions(args); } } private static void processEnvironmentVariable(String variable) { String laxVAR = System.getProperty("lax.nl.env." + variable); if (laxVAR != null) { System.setProperty(variable, laxVAR); } } /** * Set the program variables and flags based on command line args */ void getOptions(String[] args) { realmUrl = System.getProperty("RNAME", null); if (realmUrl == null) { showUsageAndExit(); } fileName = System.getProperty("FILE"); if (fileName == null) { showUsageAndExit(); } if (!new File(fileName).exists()) { System.out.println("The specified file does not exist"); showUsageAndExit(); } if (args == null) { showUsageAndExit(); } importParameters = ImportExportParametersBuilder.createParametersBuilder(); // set what will be imported based on command line arguments boolean disableCluster = false; for (String arg : args) { if (arg.equals("-all")) { importParameters.enableAll(); } else if (arg.equalsIgnoreCase("-nocluster")) { disableCluster = true; } else if (arg.equals("-realms")) { importParameters.setRealmsProcessing(true); } else if (arg.equals("-cluster")) { importParameters.setClusterProcessing(true); } else if (arg.equals("-realmacl")) { importParameters.setRealmAclProcessing(true); } else if (arg.equals("-realmcfg")) { importParameters.setRealmCfgProcessing(true); } else if (arg.equals("-channels")) { importParameters.setChannelsProcessing(true); } else if (arg.startsWith("-channelfilter")) { importParameters.setChannelfilter(getFilter(arg)); } else if (arg.equals("-channelacls")) { importParameters.setChannelAclsProcessing(true); } else if (arg.equals("-joins")) { importParameters.setJoinsProcessing(true); } else if (arg.equals("-queues")) { importParameters.setQueuesProcessing(true); } else if (arg.startsWith("-queuefilter")) { importParameters.setQueuefilter(getFilter(arg)); } else if (arg.equals("-queueacls")) { importParameters.setQueueAclsProcessing(true); } else if (arg.equals("-interfaces")) { importParameters.setInterfacesProcessing(true); } else if (arg.equals("-plugins")) { importParameters.setPluginsProcessing(true); } else if (arg.equals("-via")) { importParameters.setViaProcessing(true); } else if (arg.equals("-datagroups")) { importParameters.setDatagroupsProcessing(true); } else if (arg.startsWith("-datagroupfilter")) { importParameters.setDatagroupfilter(getFilter(arg)); } else if (arg.equals("-durables")) { importParameters.setDurablesProcessing(true); } else if (arg.equals("-jndi")) { importParameters.setJndiProcessing(true); } else if (arg.equals("-scheduler")) { importParameters.setSchedulerProcessing(true); } else if (arg.equals("-autoconvert")) { importParameters.setAutoConvert(true); } } if (disableCluster) { report("Cluster configuration not being loaded due to -noCluster flag"); importParameters.setClusterProcessing(true); } } private String getFilter(String arg) { String[] parts = arg.split("="); if(parts.length != 2) { throw new IllegalArgumentException("Wrong filter: " + arg + " Use '='!"); } return parts[1]; } private void showUsageAndExit() { Usage(); System.exit(1); } /** * Prints the usage message for this class */ private static void Usage() { System.out.println("Usage ...\n"); System.out.println("nimportrealmxml file_name\n"); System.out.println( " -all -realmacl -realmcfg -channels -durables -jndi -channelfilter= -channelacls -queues -queuefilter= -queueacls -interfaces -datagroups -datagroupfilter= -autoconvert\n"); System.out.println( "\n values are a comma separated list of java regular expressions that can filter channel, queue or datagroup names respectively."); System.out.println( "\nExample 1: nimportrealmxml test.xml -channels -channelfilter=/perf.+ \n will import only channels whose absolute path starts with /perf"); System.out.println( "\nExample 2: nimportrealmxml test.xml -channels -channelfilter=.+test \n will import only channels whose absolute path ends in test"); System.out.println( "\nExample 3: nimportrealmxml test.xml -channels -channelfilter=.*test.* \n will import only channels whose absolute path contains test"); System.out.println( "\nExample 4: nimportrealmxml test.xml -all -channelfilter=.*test.*,/perf.* \n will import everything with channels being restricted to those with absolute path containing test or starting with /perf"); System.out.println("\n\nNote: -? provides help on environment variables \n"); } private static void UsageEnv() { System.out.println("\n\n(Environment Variables) \n"); System.out.println("(RNAME) - One or more RNAME entries in the form protocol://host:port"); System.out.println(" protocol - Can be one of nsp, nhp, nsps, or nhps, where:"); System.out.println(" nsp - Specifies Nirvana Socket Protocol (nsp)"); System.out.println(" nhp - Specifies Nirvana HTTP Protocol (nhp)"); System.out.println(" nsps - Specifies Nirvana Socket Protocol Secure (nsps), i.e. using SSL/TLS"); System.out.println(" nhps - Specifies Nirvana HTTP Protocol Secure (nhps), i.e. using SSL/TLS"); System.out.println(" port - The port number of the server"); System.out.println( "\nHint: - For multiple RNAME entries, use comma separated values which will be attempted in connection weight order\n"); System.out.println( "(LOGLEVEL) - This determines how much information the nirvana api will output 0 = verbose 7 = quiet\n"); System.out.println("(CKEYSTORE) - If using SSL, the location of the keystore containing the client cert\n"); System.out.println("(CKEYSTOREPASSWD) - If using SSL, the password for the keystore containing the client cert\n"); System.out.println("(CAKEYSTORE) - If using SSL, the location of the ca truststore\n"); System.out.println("(CAKEYSTOREPASSWD) - If using SSL, the password for the ca truststore\n"); System.out.println("(HPROXY) - HTTP Proxy details in the form proxyhost:proxyport, where:"); System.out.println(" proxyhost - The HTTP proxy host"); System.out.println(" proxyport - The HTTP proxy port\n"); System.out.println("(HAUTH) - HTTP Proxy authentication details in the form user:pass, where:"); System.out.println(" user - The HTTP proxy authentication username"); System.out.println(" pass - The HTTP proxy authentication password\n"); System.exit(1); } private static void report(String line) { Date dt = new Date(); System.out.println(dt.toString() + " > " + line); } }