diff --git a/src/main/java/org/dpdirect/dpmgmt/DPCustomOp.java b/src/main/java/org/dpdirect/dpmgmt/DPCustomOp.java index 7cf8ebe..de94d8e 100644 --- a/src/main/java/org/dpdirect/dpmgmt/DPCustomOp.java +++ b/src/main/java/org/dpdirect/dpmgmt/DPCustomOp.java @@ -250,7 +250,7 @@ public boolean customPostIntercept() { } } } catch (IOException ex) { - if (!DPDBase.failOnError && !DPDBase.getLogger().isDebugEnabled()) { + if (!DPDBase.getFailOnError() && !DPDBase.getLogger().isDebugEnabled()) { DPDBase.getLogger().error(ex.getMessage()); } else { DPDBase.getLogger().error(ex.getMessage(), ex); @@ -576,7 +576,7 @@ protected void multipleSetFile() { } } } catch (IOException ex) { - if (!DPDBase.failOnError && !DPDBase.getLogger().isDebugEnabled()) { + if (!DPDBase.getFailOnError() && !DPDBase.getLogger().isDebugEnabled()) { DPDBase.getLogger().error(ex.getMessage()); } else { DPDBase.getLogger().error(ex.getMessage(), ex); diff --git a/src/main/java/org/dpdirect/dpmgmt/DPDirectBase.java b/src/main/java/org/dpdirect/dpmgmt/DPDirectBase.java index fa5ca67..9908fd6 100644 --- a/src/main/java/org/dpdirect/dpmgmt/DPDirectBase.java +++ b/src/main/java/org/dpdirect/dpmgmt/DPDirectBase.java @@ -16,11 +16,7 @@ * limitations under the License. */ -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -30,7 +26,6 @@ import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -108,80 +103,231 @@ * * @author Tim Goodwill */ -public class DPDirectBase implements DPDirectInterface { +public abstract class DPDirectBase implements DPDirectInterface { /** * Class logger. */ protected final static Logger log = Logger.getLogger(DPDirectBase.class); + /** + * Date formatter object configured with 'yyyyMMddhhmmss' format. Caller + * should synchronize on this object prior to use. + */ + protected static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMddhhmmss"); + /** * Cache of project properties. */ protected DPDirectProperties props = null; + /** Target DataPower device hostname. */ + protected String hostName = null; + + public String getHostName() { + return this.hostName; + } + + @Override + public void setHostName(String hostName) { + this.hostName = hostName; + } + + /** Target DataPower port number. Default '5550'. */ + protected String port = "5550"; + + public String getPort() { + return this.port; + } + + @Override + public void setPort(String port) { + this.port = port; + } + + /** Target DataPower username and password */ + protected Credentials credentials = null; + + public Credentials getCredentials() { + return resolveCredentials(); + } + + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + } + + @Override + public void setUserName(String userName) { + if (null == credentials) { + this.setCredentials(new Credentials()); + } + this.getCredentials().setUserName(userName); + } + + @Override + public void setUserPassword(String password) { + if (null == credentials) { + this.setCredentials(new Credentials()); + } + this.getCredentials().setPassword(password.toCharArray()); + } + /** - * The system dependent path of the NETRC file, optionally used for - * credential lookup. + * Optional Target DataPower domain. Constitutes default for chained + * operations. */ - public String netrcFilePath = null; + protected String domain = null; + + @Override + public void setDomain(String domain) { + this.domain = domain; + } + + public String getDomain() { + return this.domain; + } + + // TODO: Remove this method + public String getDefaultDomain() { + return this.domain; + } + + /** Operations immediately cease if an error is encountered. Default 'true'. */ + protected boolean failOnError = true; + + public boolean getFailOnError() { + return this.failOnError; + } + + @Override + public void setFailOnError(boolean failOnError) { + this.failOnError = failOnError; + } + + // TODO: Create generic getter/setter for rollbackOnError + + /** OutputType. Default 'PARSED'. */ + protected String outputType = "PARSED"; + + public String getOutputType() { + return this.outputType; + } + + @Override + public void setOutputType(String type) { + this.outputType=type; + } + + @Override + public void setVerbose(String verboseOutput) { + setDebug(verboseOutput); + } /** Nominated firmware level - determines SOMA and AMP version. */ protected int firmwareLevel = DEFAULT_FIRMWARE_LEVEL; + + public int getFirmwareLevel() { + return this.firmwareLevel; + } + + public void setFirmwareLevel(int firmwareLevel) { + this.firmwareLevel = firmwareLevel; + } + protected String userFirmwareLevel = "default"; - /** - * Date formatter object configured with 'yyyyMMddhhmmss' format. Caller - * should synchronize on this object prior to use. - */ - protected static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat( - "yyyyMMddhhmmss"); + public String getUserFirmwareLevel() { + return this.userFirmwareLevel; + } + + public void setUserFirmwareLevel(String userFirmwareLevel) { + this.userFirmwareLevel = userFirmwareLevel; + } + + /** Checkpoint saved, and rolled back in case of deployment errors. */ + protected String checkPointName = null; /** List of operations to build and post in order. */ protected List operationChain = new ArrayList(); - /** List of loaded SchemaLoader schemas */ - protected List schemaLoaderList = new ArrayList(); + public List getOperationChain() { + return this.operationChain; + } - /** OutputType. Default 'PARSED'. */ - protected String outputType = "PARSED"; + @Override + public Operation createOperation() { + Operation operation = new Operation(this); + addToOperationChain(operation); + return operation; + } - /** Target DataPower device hostname. */ - protected String hostName = null; + public Operation createOperation(String operationName) { + Operation operation = new Operation(this, operationName); + addToOperationChain(operation); + return operation; + } - /** Target DataPower port number. Default '5550'. */ - protected String port = "5550"; + public void addToOperationChain(Operation operation) { + getOperationChain().add(operation); + } - /** Target DataPower username and password */ - protected Credentials credentials = null; + public void addToOperationChain(int i, Operation operation) { + getOperationChain().add(i, operation); + } + + public Operation newOperation(String operationName) { + return new Operation(this, operationName); + } + + public void resetOperationChain() { + operationChain.clear(); + } + + /** List of loaded SchemaLoader schemas */ + protected List schemaLoaderList = new ArrayList(); + + public void resetSchemas() { + schemaLoaderList.clear(); + } /** - * Optional Target DataPower domain. Constitutes default for chained - * operations. + * The system dependent path of the NETRC file, optionally used for + * credential lookup. */ - protected String domain = null; + protected String netrcFilePath = null; - /** Checkpoint saved, and rolled back in case of deployment errors. */ - protected String checkPointName = null; + public String getNetrcFilePath() { + return this.netrcFilePath; + } + + public void setNetrcFilePath(String netrcFilePath) { + this.netrcFilePath = netrcFilePath; + } - /** Operations immediately cease if an error is encountered. Default 'true'. */ - protected boolean failOnError = true; - /** Output is logged. Default 'true'. */ protected boolean logOutput = true; - + /** - * Cache of the "ant-usage.txt" help file content. + * set the logOutput switch. + * @param isLogged the output be logged. */ - protected static String antUsageText = null; + public void setLogOutput(boolean isLogged){ + this.logOutput = isLogged; + } /** - * Print ant help to the console. + * get the logger attached to this class. + * @return logger */ - public static void help() { - antHelp(); + public Logger getLogger() { + return log; } + /** + * Cache of the "ant-usage.txt" help file content. + */ + protected static String antUsageText = null; + /** * Print ant task help to System.out. */ @@ -194,76 +340,59 @@ public static void antHelp() { } } + /** + * Print ant help to the console. + */ + public static void help() { + antHelp(); + } + + /** + * @return this instance + */ + protected DPDirectBase getDPDInstance() { + return this; + } + /** * Constructs a new DPDirect class. */ public DPDirectBase() { - log.debug("Constructing new DPDirect class intance"); + log.debug("Constructing new DPDirect class instance"); // Load properties try { this.props = new DPDirectProperties(); try { - setNetrcFilePath(props - .getProperty(DPDirectProperties.NETRC_FILE_PATH_KEY)); - setFirmware(props - .getProperty(DPDirectProperties.FIRMWARE_LEVEL_KEY)); + setNetrcFilePath(props.getProperty(DPDirectProperties.NETRC_FILE_PATH_KEY)); + setFirmware(props.getProperty(DPDirectProperties.FIRMWARE_LEVEL_KEY)); } catch (Exception e) { this.firmwareLevel = DEFAULT_FIRMWARE_LEVEL; } } catch (IOException ex) { - if (!failOnError && !log.isDebugEnabled()) { + if (!getFailOnError() && !log.isDebugEnabled()) { log.error(ex.getMessage()); } else { log.error(ex.getMessage(), ex); } } // Cache the ant usage text file content. - InputStream inputStream = DPDirectBase.class - .getResourceAsStream(Constants.ANT_USAGE_TEXT_FILE_PATH); - try { - byte[] fileBytes = FileUtils.readInputStreamBytes(inputStream); - antUsageText = new String(fileBytes); - } catch (IOException ex) { - log.error(ex.getMessage(), ex); - } finally { - try { - inputStream.close(); - } catch (Exception e) { - // Ignore. - } - } - - } + InputStream inputStream = DPDirectBase.class.getResourceAsStream(Constants.ANT_USAGE_TEXT_FILE_PATH); - /** - * Constructs a new DPDirect class. - * - * @param schemaDirectory - * the directory in which to find the SOMA and AMP schema. - */ - public DPDirectBase(String schemaDirectory) { - this(); - try { - schemaLoaderList.add(new SchemaLoader(schemaDirectory + "/" - + Constants.SOMA_MGMT_SCHEMA_NAME)); - log.debug("SOMAInstance schemaURI : " - + schemaLoaderList.get(schemaLoaderList.size() - 1) - .getSchemaURI()); - } catch (Exception ex) { - if (!failOnError && !log.isDebugEnabled()) { - log.error(ex.getMessage()); - } else { + if (inputStream != null) { + try { + byte[] fileBytes = FileUtils.readInputStreamBytes(inputStream); + antUsageText = new String(fileBytes); + } catch (IOException ex) { log.error(ex.getMessage(), ex); + } finally { + try { + inputStream.close(); + } catch (Exception e) { + // Ignore. + } } } } - - /** - * @return this instance - */ - protected DPDirectBase getDPDInstance() { - return this; - } /* (non-Javadoc) * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#execute() @@ -279,46 +408,11 @@ public void execute() { this.generateOperationXML(); this.postOperationXML(); } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getOperationChain() - */ - @Override - public List getOperationChain() { - return this.operationChain; - } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#addToOperationChain(org.dpdirect.dpmgmt.DPDirect.Operation) - */ - public void addToOperationChain(Operation operation) { - getOperationChain().add(operation); - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#addToOperationChain(org.dpdirect.dpmgmt.DPDirect.Operation) - */ - public void addToOperationChain(int i, Operation operation) { - getOperationChain().add(i, operation); - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#resetOperationChain() - */ - @Override - public void resetOperationChain() { - operationChain.clear(); - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#resetSchemas() + /** + * Set the schema paths for the SOMA and AMP operations. The schema paths + * are determined by the firmware level. */ - @Override - public void resetSchemas() { - schemaLoaderList.clear(); - } - - @Override public void setSchema() { log.debug("firmwareLevel: " + firmwareLevel); log.debug("userFirmwareLevel: " + userFirmwareLevel); @@ -390,10 +484,11 @@ private void addSchema(String path, String label, Integer index) throws Exceptio log.info(label + " schema loaded successfully. URI: " + loader.getSchemaURI()); } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#processPropertiesFile(java.lang.String) + /** + * Load a properties file and process the properties. + * + * @param propFileName the properties file name. */ - @Override public void processPropertiesFile(String propFileName) { final String PROP_SUFFIX = ".properties"; String opName = null; @@ -432,10 +527,12 @@ public void processPropertiesFile(String propFileName) { } } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setGlobalOption(java.lang.String, java.lang.String) + /** + * Set the global options for the DPDirect instance. + * + * @param name the option name. + * @param value the option value. */ - @Override public void setGlobalOption(String name, String value) { if (Constants.HOST_NAME_OPT_NAME.equalsIgnoreCase(name)) { this.setHostName(value); @@ -474,170 +571,43 @@ public void setGlobalOption(String name, String value) { } } - - /** - * get the logger attached to this class. - * @return logger - */ - public Logger getLogger() { - return log; - } - - /** - * set the logOutput switch. - * @param isLogged the output be logged. - */ - public void setLogOutput(boolean isLogged){ - this.logOutput = isLogged; - } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getOutputType() - */ - @Override - public String getOutputType() { - return this.outputType; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setOutputType(java.lang.String) - */ - @Override - public void setOutputType(String type) { - this.outputType=type; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setHostName(java.lang.String) - */ - @Override - public void setHostName(String hostName) { - this.hostName = hostName; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setPort(java.lang.String) - */ - @Override - public void setPort(String port) { - this.port = port; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getPort() - */ - @Override - public String getPort() { - return port; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setUserName(java.lang.String) + /** + * Resolve the credentials for the target host. If credentials are not + * provided by the command line or ant task, then the Netrc file is checked + * for the target host. + * + * @return the resolved credentials. */ - @Override - public void setUserName(String userName) { - if (null == credentials) { - this.setCredentials(new Credentials()); + public Credentials resolveCredentials() { + if (credentials != null) { + return credentials; } - this.getCredentials().setUserName(userName); - } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setUserPassword(java.lang.String) - */ - @Override - public void setUserPassword(String password) { - if (null == credentials) { - this.setCredentials(new Credentials()); + if (getHostName() == null) { + log.error("Failed to resolve credentials from Netrc config. No target 'hostName' value has been provided"); + return null; } - this.getCredentials().setPassword(password.toCharArray()); - } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getCredentials() - */ - @Override - public Credentials getCredentials() { - // If credentials are null then they have not been provided by the - // command line or - // ant task and we default to Netrc file lookup. - if (null == credentials) { - if (null == getHostName()) { - log.error("Failed to resolve credentials from Netrc config. No target 'hostName' value has been provided"); - return null; + try { + log.debug("Resolving credentials from Netrc config."); + credentials = getCredentialsFromNetrcConfig(getHostName()); + if (log.isDebugEnabled() && credentials != null) { + log.debug("Resulting username from Netrc config: username=" + credentials.getUserName()); } - try { - log.debug("Resolving credentials from Netrc config."); - credentials = getCredentialsFromNetrcConfig(getHostName()); - if (log.isDebugEnabled()) { - log.debug("Resulting username from Netrc config: username=" - + ((null == credentials) ? null : credentials - .getUserName())); - } - if (null == credentials) { - log.error("Failed to resolve credentials. Credential have not been provided for the target host either by command line or ant task or Netrc config file."); - } - } catch (Exception ex) { - log.error( - "Failed to resolve credentials from Netrc config. Error msg: " - + ex.getMessage(), ex); + + if (credentials == null) { + log.error("Failed to resolve credentials. Credential have not been provided for the target host either by command line or ant task or Netrc config file."); } + } catch (Exception ex) { + log.error("Failed to resolve credentials from Netrc config. Error msg: " + ex.getMessage(), ex); } return credentials; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setCredentials(org.dpdirect.utils.Credentials) - */ - @Override - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getHostName() - */ - @Override - public String getHostName() { - return this.hostName; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setDomain(java.lang.String) - */ - @Override - public void setDomain(String domain) { - this.domain = domain; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getDomain() - */ - @Override - public String getDomain() { - return this.domain; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getDomain() - */ - public String getDefaultDomain() { - return this.domain; - } - - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setVerbose(java.lang.String) - */ - @Override - public void setVerbose(String verboseOutput) { - setDebug(verboseOutput); - } - /* (non-Javadoc) * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setDebug(java.lang.String) */ - @Override public void setDebug(String debugOutput) { if (Constants.TRUE_OPT_VALUE.equalsIgnoreCase(debugOutput)) { log.setLevel(org.apache.log4j.Level.DEBUG); @@ -646,14 +616,6 @@ public void setDebug(String debugOutput) { } } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setFailOnError(boolean) - */ - @Override - public void setFailOnError(boolean failOnError) { - this.failOnError = failOnError; - } - /* (non-Javadoc) * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setRollbackOnError(boolean) */ @@ -673,10 +635,6 @@ public void setRollbackOnError(boolean enableRollback) { } } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#removeCheckpoint() - */ - @Override public void removeCheckpoint() { Operation removeCheckpoint = new Operation(this, Constants.REMOVE_CHECKPOINT_OP_NAME); removeCheckpoint.addOption(Constants.CHK_NAME_OP_NAME, checkPointName); @@ -686,39 +644,6 @@ public void removeCheckpoint() { parseResponseMsg(removeCheckpoint, false); } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#createOperation() - */ - @Override - public Operation createOperation() { - Operation operation = new Operation(this); - addToOperationChain(operation); - return operation; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#createOperation(java.lang.String) - */ - @Override - public Operation createOperation(String operationName) { - Operation operation = new Operation(this, operationName); - addToOperationChain(operation); - return operation; - } - - public Operation newOperation(String operationName) { - return new Operation(this, operationName); - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#addOperation(java.lang.String) - */ - @Override - public void addOperation(String operationName) { - Operation operation = new Operation(this, operationName); - addToOperationChain(operation); - } - /** * Iterate through the operationChain to generate the SOMA and AMP XML. Will * exit upon failure to generate valid XML. @@ -734,10 +659,6 @@ protected void generateOperationXML() { } } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#generateXMLInstance(org.dpdirect.dpmgmt.DPDirect.Operation) - */ - @Override public String generateXMLInstance(Operation operation) { String xmlString = null; SchemaLoader workingInstance = null; @@ -847,10 +768,6 @@ public String generateXMLInstance(Operation operation) { return xmlString; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#postOperationXML() - */ - @Override public void postOperationXML() { Credentials credentials = getCredentials(); @@ -883,12 +800,7 @@ public void postOperationXML() { removeCheckpoint(); } } - - /** - * Poll for the desired waitFor result. - * - * @param operation : the operation to poll. - */ + public void pollForResult(Operation operation) throws Exception { String responseString = null; int numberOfPolls = 0; @@ -953,10 +865,6 @@ public void pollForResult(Operation operation) throws Exception { } } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#postXMLInstance(org.dpdirect.dpmgmt.DPDirect.Operation, org.dpdirect.utils.Credentials) - */ - @Override public String postXMLInstance(Operation operation, Credentials credentials) { // String endPoint = operation.getEndPoint(); String xmlResponse = null; @@ -1016,10 +924,6 @@ public String postXMLInstance(Operation operation, Credentials credentials) { return xmlResponse; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#parseResponseMsg(org.dpdirect.dpmgmt.DPDirect.Operation, boolean) - */ - @Override public String parseResponseMsg(Operation operation, boolean handleError) { List parseResult = new ArrayList(); org.apache.log4j.Level logLevel = org.apache.log4j.Level.INFO; @@ -1054,10 +958,6 @@ public String parseResponseMsg(Operation operation, boolean handleError) { return parsedText; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#isSuccessResponse(org.dpdirect.dpmgmt.DPDirect.Operation) - */ - @Override public boolean isSuccessResponse(Operation operation) { boolean success = false; List parseResult = new ArrayList(); @@ -1078,10 +978,6 @@ public boolean isSuccessResponse(Operation operation) { return success; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#processResponse(org.dpdirect.dpmgmt.DPDirect.Operation) - */ - @Override public String processResponse(Operation operation) { String parsedText = null; @@ -1179,8 +1075,6 @@ private boolean evaluateXPath(String xml, String xpath) throws XPathExpressionEx * String : the current parsed result string returned. * @param logLevel * org.apache.log4j.Level : the log level of the error. - * @throws Exception - * - throws parse errors. */ protected void errorHandler(Operation operation, String errorResponse, org.apache.log4j.Level logLevel) { @@ -1241,7 +1135,7 @@ protected void logInfo(Operation operation, String output){ log.info(output); } } - + protected void logWarn(Operation operation, String errorResponse){ if (!logOutput) { System.out.println("WARNING: " + errorResponse); @@ -1250,7 +1144,7 @@ protected void logWarn(Operation operation, String errorResponse){ log.warn("errorResponse:\n" + errorResponse); } } - + protected void logError(Operation operation, String errorResponse){ if (!logOutput) { System.out.println("ERROR: " + errorResponse); @@ -1287,10 +1181,6 @@ protected boolean restoreCheckpoint() { return success; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#generateAndPost(org.dpdirect.dpmgmt.DPDirect.Operation) - */ - @Override public String generateAndPost(Operation operation) { // Discern the target operation schema, and assign the DP device // endpoint. @@ -1309,10 +1199,11 @@ public String generateAndPost(Operation operation) { return xmlResponse; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getCredentialsFromNetrcConfig(java.lang.String) + /** + * Get the credentials from the Netrc configuration file. + * @param hostName the host name to lookup. + * @return the credentials. */ - @Override public Credentials getCredentialsFromNetrcConfig(String hostName) { if (null != hostName) { try { @@ -1374,22 +1265,4 @@ public void setFirmware(String firmwareLevel) { this.firmwareLevel = intLevel; } - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#getNetrcFilePath() - */ - @Override - public String getNetrcFilePath() { - return netrcFilePath; - } - - /* (non-Javadoc) - * @see org.dpdirect.dpmgmt.DPDirectBaseInterface#setNetrcFilePath(java.lang.String) - */ - @Override - public void setNetrcFilePath(String netrcFilePath) { - this.netrcFilePath = netrcFilePath; - } - - - -} +} \ No newline at end of file diff --git a/src/main/java/org/dpdirect/dpmgmt/DPDirectInterface.java b/src/main/java/org/dpdirect/dpmgmt/DPDirectInterface.java index fd8454f..838aab3 100644 --- a/src/main/java/org/dpdirect/dpmgmt/DPDirectInterface.java +++ b/src/main/java/org/dpdirect/dpmgmt/DPDirectInterface.java @@ -19,8 +19,6 @@ import java.util.List; import org.apache.tools.ant.BuildException; -import org.dpdirect.dpmgmt.Operation; -import org.dpdirect.utils.Credentials; public interface DPDirectInterface { @@ -31,67 +29,7 @@ public interface DPDirectInterface { * if there is a fatal error running the task. */ public abstract void execute() throws BuildException; - - /** - * Returnss operationChain list - */ - public abstract List getOperationChain(); - - /** - * Clears operationChain list - */ - public abstract void resetOperationChain(); - - /** - * Clears loaded SchemaLoader classes - */ - public abstract void resetSchemas(); - - /** - * Set the default schema if not already set. These versions are bundled in - * the jar. - */ - public abstract void setSchema(); - /** - * Setter to load an alternative or updated SOMA schema. - * - * @param schemaPath - * String : the path to the SOMA schema - */ - public abstract void setSchema(String schemaPath); - - /** - * Read and process a named properties file. Sets global properties. - * - * @param propFileName - * String : the name of the properties file. - */ - public abstract void processPropertiesFile(String propFileName); - - /** - * Setter global options via name value pairs. Used by command line - * invocation. - * - * @param name - * the option name - * @param value - * the option value - */ - public abstract void setGlobalOption(String name, String value); - - /** - * Get the output type. - */ - public abstract String getOutputType(); - - /** - * Sets the output type. - * - * @param type - * the output type - of XML, LINES or PARSED. - */ - public abstract void setOutputType(String type); /** * Sets the target DP device hostName. @@ -103,17 +41,12 @@ public interface DPDirectInterface { /** * Sets the target DP device XML interface port. - * + * * @param port * the target port number. */ public abstract void setPort(String port); - /** - * @return the port - */ - public abstract String getPort(); - /** * Sets the target DP device userName. * @@ -125,17 +58,11 @@ public interface DPDirectInterface { /** * Sets the target DP device password for the authorised user. * - * @param userName + * @param password * the target DP device password for the authorised user. */ public abstract void setUserPassword(String password); - public abstract Credentials getCredentials(); - - public abstract void setCredentials(Credentials credentials); - - public abstract String getHostName(); - /** * Sets the default DP domain for a set of operations. Individual operations * may assume the default domain, or explicitly over-ride it. @@ -145,24 +72,6 @@ public interface DPDirectInterface { */ public abstract void setDomain(String domain); - public abstract String getDomain(); - - /** - * Sets the log-level and verbosity of output. - * - * @param verboseOutput - * Produce verbose output - 'true' or 'false'. - */ - public abstract void setVerbose(String verboseOutput); - - /** - * Sets the log-level. - * - * @param debugOutput - * Produce debug output - 'true' or 'false'. - */ - public abstract void setDebug(String debugOutput); - /** * Sets the failOnError option. Setting to 'true' fails and immediately * ceases the build when errors are returned. @@ -183,103 +92,20 @@ public interface DPDirectInterface { public abstract void setRollbackOnError(boolean enableRollback); /** - * Setter to save a checkpoint and rollback if the build should fail. - * - * @param enableRollback - * boolean : true to save a checkpoint and rollback in case of - * failure. - */ - public abstract void removeCheckpoint(); - - /** - * Default method to create a nested operation. - */ - public abstract Operation createOperation(); - - /** - * Method to create a nested operation by name. - * - * @param operationName - * String : name corresponding to a valid SOMA or AMP operation. - * @return operation created. - */ - public abstract Operation createOperation(String operationName); - - /** - * Add a nested operation by name. Utilised by Ant task for nested - * instances. - * - * @param operationName - * String : name corresponding to a valid SOMA or AMP operation. - */ - public abstract void addOperation(String operationName); - - /** - * Generate the SOMA and AMP XML for each operation. - * - * @param operation - * Operation : the current operation object. - * @throws Exception - * - if valid XML cannot be generated. - */ - public abstract String generateXMLInstance(Operation operation); - - /** - * Iterate through the SOMA and AMP XML for each operation, post and parse - * response. XML will have been validated at this point. Will fail the build - * and exit(1) upon error if 'failOnError is set to true (default=true). - * Will restore to checkpoint and exit(2) upon error if rollbackOnError is - * set to true (default=false). - */ - public abstract void postOperationXML(); - - public abstract String parseResponseMsg(Operation operation, - boolean handleError); - - public abstract boolean isSuccessResponse(Operation operation); - - /** - * Process the XML response for an operation. - * - * @param operation - * Operation : the current operation object. - * @return parsed response. - */ - public abstract String processResponse(Operation operation); - - /** - * Generate the XML for the provided operation and post to device. - * - * @param operation - * the current operation object - */ - public abstract String generateAndPost(Operation operation); - - /** - * Post SOMA or AMP XML for an individual operation. + * Sets the output type. * - * @param operation - * the current operation object. - * @param credentials - * authorised username and password for the device. - * @throws Exception - * if unable to post, or other critical errors encountered. + * @param type + * the output type - of XML, LINES or PARSED. */ - public abstract String postXMLInstance(Operation operation, - Credentials credentials); + public abstract void setOutputType(String type); /** - * Gets DataPower logon credentials from a NETRC file (on windows "_netrc" - * located in the user home drive). - * - * @param hostName - * the host name to match in the NETRC file. + * Sets the log-level and verbosity of output. * - * @return a Base64 encoded basic authorisation header string for the given - * host; or null if there is no NETRC file or no entry in the NETRC - * file for the host. + * @param verboseOutput + * Produce verbose output - 'true' or 'false'. */ - public abstract Credentials getCredentialsFromNetrcConfig(String hostName); + public abstract void setVerbose(String verboseOutput); /** * @param firmwareLevel @@ -288,14 +114,14 @@ public abstract String postXMLInstance(Operation operation, public abstract void setFirmware(String firmwareLevel); /** - * @return the netrcFilePath + * Set the default schema if not already set. These versions are bundled in + * the jar. */ - public abstract String getNetrcFilePath(); + public abstract void setSchema(String schema); /** - * @param netrcFilePath - * the netrcFilePath to set + * Default method to create a nested operation. */ - public abstract void setNetrcFilePath(String netrcFilePath); + public abstract Operation createOperation(); } \ No newline at end of file diff --git a/src/main/java/org/dpdirect/dpmgmt/DPDirectTask.java b/src/main/java/org/dpdirect/dpmgmt/DPDirectTask.java index 6a7fc12..704a6f6 100644 --- a/src/main/java/org/dpdirect/dpmgmt/DPDirectTask.java +++ b/src/main/java/org/dpdirect/dpmgmt/DPDirectTask.java @@ -64,60 +64,23 @@ * @author Tim Goodwill */ public class DPDirectTask extends Task implements DPDirectInterface { - - private final DPDirectBase base = new - DPDirectBase(); - - public DPDirectTask() {} - - @Override - public void execute() throws BuildException { - base.execute(); - } - - @Override - public List getOperationChain() { - return (List)base.getOperationChain(); - } - - @Override - public void resetOperationChain() { - base.resetOperationChain(); - } - - @Override - public void resetSchemas() { - base.resetSchemas(); - } - - @Override - public void setSchema() { - base.setSchema(); - } - - @Override - public void setSchema(String schemaPath) { - base.setSchema(schemaPath); - } - @Override - public void processPropertiesFile(String propFileName) { - base.processPropertiesFile(propFileName); - } + private final DPDirectBase base = new DPDirectTaskBase(); - @Override - public void setGlobalOption(String name, String value) { - base.setGlobalOption(name, value); + private static class DPDirectTaskBase extends DPDirectBase { + //@Override + //public String processResponse(Operation operation) { + // System.out.print("highjacking processResponse"); + // return super.processResponse(operation); + //} } - @Override - public String getOutputType() { - return base.getOutputType(); - } + public DPDirectTask() {} @Override - public void setOutputType(String type) { - base.setOutputType(type); + public void execute() throws BuildException { + System.out.println(getProject()); + base.execute(); } @Override @@ -125,16 +88,6 @@ public void setHostName(String hostName) { base.setHostName(hostName); } - @Override - public void setPort(String port) { - base.setPort(port); - } - - @Override - public String getPort() { - return base.getPort(); - } - @Override public void setUserName(String userName) { base.setUserName(userName); @@ -146,18 +99,8 @@ public void setUserPassword(String password) { } @Override - public Credentials getCredentials() { - return base.getCredentials(); - } - - @Override - public void setCredentials(Credentials credentials) { - base.setCredentials(credentials); - } - - @Override - public String getHostName() { - return base.getHostName(); + public void setPort(String port) { + base.setPort(port); } @Override @@ -165,21 +108,6 @@ public void setDomain(String domain) { base.setDomain(domain); } - @Override - public String getDomain() { - return base.getDomain(); - } - - @Override - public void setVerbose(String verboseOutput) { - base.setVerbose(verboseOutput); - } - - @Override - public void setDebug(String debugOutput) { - base.setDebug(debugOutput); - } - @Override public void setFailOnError(boolean failOnError) { base.setFailOnError(failOnError); @@ -191,63 +119,13 @@ public void setRollbackOnError(boolean enableRollback) { } @Override - public void removeCheckpoint() { - base.removeCheckpoint(); - } - - @Override - public Operation createOperation() { - return (Operation) base.createOperation(); - } - - @Override - public Operation createOperation(String operationName) { - return base.createOperation(operationName); - } - - @Override - public void addOperation(String operationName) { - base.addOperation(operationName); - } - - @Override - public String generateXMLInstance(Operation operation) { - return base.generateXMLInstance(operation); - } - - @Override - public void postOperationXML() { - base.postOperationXML(); - } - - @Override - public String parseResponseMsg(Operation operation, boolean handleError) { - return base.parseResponseMsg(operation, handleError); - } - - @Override - public boolean isSuccessResponse(Operation operation) { - return base.isSuccessResponse(operation); - } - - @Override - public String processResponse(Operation operation) { - return base.processResponse(operation); - } - - @Override - public String generateAndPost(Operation operation) { - return base.generateAndPost(operation); - } - - @Override - public String postXMLInstance(Operation operation, Credentials credentials) { - return base.postXMLInstance(operation, credentials); + public void setOutputType(String type) { + base.setOutputType(type); } @Override - public Credentials getCredentialsFromNetrcConfig(String hostName) { - return base.getCredentialsFromNetrcConfig(hostName); + public void setVerbose(String verboseOutput) { + base.setVerbose(verboseOutput); } @Override @@ -256,14 +134,13 @@ public void setFirmware(String firmwareLevel) { } @Override - public String getNetrcFilePath() { - return base.getNetrcFilePath(); + public void setSchema(String schema) { + base.setSchema(schema); } @Override - public void setNetrcFilePath(String netrcFilePath) { - base.setNetrcFilePath(netrcFilePath); + public Operation createOperation() { + return base.createOperation(); } - }