Search in sources :

Example 91 with JDOMException

use of org.jdom.JDOMException in project liferay-ide by liferay.

the class InitConfigureProjectPage method _removeIvyPrivateSetting.

@SuppressWarnings("unchecked")
private void _removeIvyPrivateSetting(IPath sdkLocation) throws CoreException {
    IPath ivySettingPath = sdkLocation.append("ivy-settings.xml");
    File ivySettingFile = ivySettingPath.toFile();
    SAXBuilder builder = new SAXBuilder(false);
    builder.setValidation(false);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    try (InputStream ivyInput = Files.newInputStream(ivySettingFile.toPath())) {
        if (ivySettingFile.exists()) {
            Document doc = builder.build(ivyInput);
            Element itemRem = null;
            Element elementRoot = doc.getRootElement();
            List<Element> resolversElements = elementRoot.getChildren("resolvers");
            for (Iterator<Element> resolversIterator = resolversElements.iterator(); resolversIterator.hasNext(); ) {
                Element resolversElement = resolversIterator.next();
                List<Element> chainElements = resolversElement.getChildren("chain");
                for (Iterator<Element> chainIterator = chainElements.iterator(); chainIterator.hasNext(); ) {
                    Element chainElement = chainIterator.next();
                    List<Element> resolverElements = chainElement.getChildren("resolver");
                    for (Iterator<Element> resolverIterator = resolverElements.iterator(); resolverIterator.hasNext(); ) {
                        Element resolverItem = resolverIterator.next();
                        String resolverRefItem = resolverItem.getAttributeValue("ref");
                        if (resolverRefItem.equals("liferay-private")) {
                            resolverIterator.remove();
                            itemRem = resolverItem;
                        }
                    }
                }
                elementRoot.removeContent(itemRem);
                List<Element> ibiblioElements = resolversElement.getChildren("ibiblio");
                for (Iterator<Element> ibiblioIterator = ibiblioElements.iterator(); ibiblioIterator.hasNext(); ) {
                    Element ibiblioElement = ibiblioIterator.next();
                    String liferayPrivateName = ibiblioElement.getAttributeValue("name");
                    if (liferayPrivateName.equals("liferay-private")) {
                        ibiblioIterator.remove();
                        itemRem = ibiblioElement;
                    }
                }
                elementRoot.removeContent(itemRem);
            }
            _saveXML(ivySettingFile, doc);
        }
    } catch (CoreException | IOException | JDOMException e) {
        ProjectUI.logError(e);
        throw new CoreException(StatusBridge.create(Status.createErrorStatus("Failed to remove Liferay private url configuration of ivy-settings.xml.", e)));
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) Element(org.jdom.Element) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 92 with JDOMException

use of org.jdom.JDOMException in project core by jcryptool.

the class FlexiProviderPlugin method getAlgorithmsXML.

/**
 * Reads the algorithms.xml file and creates a document object.
 *
 * @return	A jdom document
 */
public static Document getAlgorithmsXML() {
    URL xmlFile = FlexiProviderPlugin.getDefault().getBundle().getEntry("/xml/algorithms.xml");
    SAXBuilder builder = new SAXBuilder();
    try {
        return builder.build(xmlFile);
    } catch (JDOMException e) {
        LogUtil.logError(PLUGIN_ID, e);
    } catch (IOException e) {
        LogUtil.logError(PLUGIN_ID, e);
    }
    return null;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) URL(java.net.URL)

Example 93 with JDOMException

use of org.jdom.JDOMException in project oozie by apache.

the class DecisionActionExecutor method start.

@SuppressWarnings("unchecked")
public void start(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.info("Starting action");
    try {
        String confStr = action.getConf();
        context.setStartData("-", "-", "-");
        Element conf = XmlUtils.parseXml(confStr);
        Namespace ns = conf.getNamespace();
        String externalState = null;
        for (Element eval : (List<Element>) conf.getChildren("case", ns)) {
            if (TRUE.equals(eval.getTextTrim())) {
                externalState = eval.getAttributeValue("to");
                break;
            }
        }
        if (externalState == null) {
            Element def = conf.getChild("default", ns);
            if (def != null) {
                externalState = def.getAttributeValue("to");
            }
        }
        if (externalState == null) {
            throw new IllegalStateException("Transition cannot be NULL");
        }
        // for decision we are piggybacking on external status to transfer the transition,
        // the {@link ActionEndCommand} does the special handling of setting it as signal value.
        context.setExecutionData(externalState, null);
    } catch (JDOMException ex) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, XML_ERROR, ex.getMessage(), ex);
    }
}
Also used : Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

Example 94 with JDOMException

use of org.jdom.JDOMException in project oozie by apache.

the class CoordActionStartXCommand method mergeConfig.

/**
 * Create config to pass to WF Engine 1. Get createdConf from coord_actions table 2. Get actionXml from
 * coord_actions table. Extract all 'property' tags and merge createdConf (overwrite duplicate keys). 3. Extract
 * 'app-path' from actionXML. Create a new property called 'oozie.wf.application.path' and merge with createdConf
 * (overwrite duplicate keys) 4. Read contents of config-default.xml in workflow directory. 5. Merge createdConf
 * with config-default.xml (overwrite duplicate keys). 6. Results is runConf which is saved in coord_actions table.
 * Merge Action createdConf with actionXml to create new runConf with replaced variables
 *
 * @param action CoordinatorActionBean
 * @return Configuration
 * @throws CommandException
 */
private Configuration mergeConfig(CoordinatorActionBean action) throws CommandException {
    String createdConf = action.getCreatedConf();
    String actionXml = action.getActionXml();
    Element workflowProperties = null;
    try {
        workflowProperties = XmlUtils.parseXml(actionXml);
    } catch (JDOMException e1) {
        log.warn("Configuration parse error in:" + actionXml);
        throw new CommandException(ErrorCode.E1005, e1.getMessage(), e1);
    }
    // generate the 'runConf' for this action
    // Step 1: runConf = createdConf
    Configuration runConf = null;
    try {
        runConf = new XConfiguration(new StringReader(createdConf));
    } catch (IOException e1) {
        log.warn("Configuration parse error in:" + createdConf);
        throw new CommandException(ErrorCode.E1005, e1.getMessage(), e1);
    }
    // Step 2: Merge local properties into runConf
    // extract 'property' tags under 'configuration' block in the
    // coordinator.xml (saved in actionxml column)
    // convert Element to XConfiguration
    Element configElement = workflowProperties.getChild("action", workflowProperties.getNamespace()).getChild("workflow", workflowProperties.getNamespace()).getChild("configuration", workflowProperties.getNamespace());
    if (configElement != null) {
        String strConfig = XmlUtils.prettyPrint(configElement).toString();
        Configuration localConf;
        try {
            localConf = new XConfiguration(new StringReader(strConfig));
        } catch (IOException e1) {
            log.warn("Configuration parse error in:" + strConfig);
            throw new CommandException(ErrorCode.E1005, e1.getMessage(), e1);
        }
        // copy configuration properties in coordinator.xml to the runConf
        XConfiguration.copy(localConf, runConf);
    }
    // Step 3: Extract value of 'app-path' in actionxml, and save it as a
    // new property called 'oozie.wf.application.path'
    // WF Engine requires the path to the workflow.xml to be saved under
    // this property name
    String appPath = workflowProperties.getChild("action", workflowProperties.getNamespace()).getChild("workflow", workflowProperties.getNamespace()).getChild("app-path", workflowProperties.getNamespace()).getValue();
    // Copying application path in runconf.
    runConf.set("oozie.wf.application.path", appPath);
    // Step 4: Extract the runconf and copy the rerun config to runconf.
    if (runConf.get(CoordRerunXCommand.RERUN_CONF) != null) {
        Configuration rerunConf = null;
        try {
            rerunConf = new XConfiguration(new StringReader(runConf.get(CoordRerunXCommand.RERUN_CONF)));
            XConfiguration.copy(rerunConf, runConf);
        } catch (IOException e) {
            log.warn("Configuration parse error in:" + rerunConf);
            throw new CommandException(ErrorCode.E1005, e.getMessage(), e);
        }
        runConf.unset(CoordRerunXCommand.RERUN_CONF);
    }
    return runConf;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) StringReader(java.io.StringReader) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 95 with JDOMException

use of org.jdom.JDOMException in project oozie by apache.

the class SshActionExecutor method check.

/**
 * Check ssh action status.
 *
 * @param context action execution context.
 * @param action action object.
 * @throws org.apache.oozie.action.ActionExecutorException
 */
@Override
public void check(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.trace("check() start for action={0}", action.getId());
    Status status = getActionStatus(context, action);
    boolean captureOutput = false;
    try {
        Element eConf = XmlUtils.parseXml(action.getConf());
        Namespace ns = eConf.getNamespace();
        captureOutput = eConf.getChild("capture-output", ns) != null;
    } catch (JDOMException ex) {
        throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_XML_PARSE_FAILED", "unknown error", ex);
    }
    LOG.debug("Capture Output: {0}", captureOutput);
    if (status == Status.OK) {
        if (captureOutput) {
            String outFile = getRemoteFileName(context, action, "stdout", false, true);
            String dataCommand = SSH_COMMAND_BASE + action.getTrackerUri() + " cat " + outFile;
            LOG.debug("Ssh command [{0}]", dataCommand);
            try {
                final Process process = Runtime.getRuntime().exec(dataCommand.split("\\s"));
                final StringBuffer outBuffer = new StringBuffer();
                final StringBuffer errBuffer = new StringBuffer();
                boolean overflow = false;
                drainBuffers(process, outBuffer, errBuffer, maxLen);
                LOG.trace("outBuffer={0}", outBuffer);
                LOG.trace("errBuffer={0}", errBuffer);
                if (outBuffer.length() > maxLen) {
                    overflow = true;
                }
                if (overflow) {
                    throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_OUTPUT_EXCEED_MAX_LEN", "unknown error");
                }
                context.setExecutionData(status.toString(), PropertiesUtils.stringToProperties(outBuffer.toString()));
                LOG.trace("Execution data set. status={0}, properties={1}", status, PropertiesUtils.stringToProperties(outBuffer.toString()));
            } catch (Exception ex) {
                throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "ERR_UNKNOWN_ERROR", "unknown error", ex);
            }
        } else {
            LOG.trace("Execution data set to null. status={0}", status);
            context.setExecutionData(status.toString(), null);
        }
    } else {
        if (status == Status.ERROR) {
            LOG.warn("Execution data set to null in ERROR");
            context.setExecutionData(status.toString(), null);
        } else {
            LOG.warn("Execution data not set");
            context.setExternalStatus(status.toString());
        }
    }
    LOG.trace("check() end for action={0}", action);
}
Also used : Status(org.apache.oozie.client.WorkflowAction.Status) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Aggregations

JDOMException (org.jdom.JDOMException)137 IOException (java.io.IOException)103 Element (org.jdom.Element)82 Document (org.jdom.Document)49 SAXBuilder (org.jdom.input.SAXBuilder)45 File (java.io.File)22 StringReader (java.io.StringReader)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 ArrayList (java.util.ArrayList)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 List (java.util.List)9 CommandException (org.apache.oozie.command.CommandException)9 InputStream (java.io.InputStream)8 Namespace (org.jdom.Namespace)8 SAXException (org.xml.sax.SAXException)8 URL (java.net.URL)7 HashMap (java.util.HashMap)7 THashMap (gnu.trove.THashMap)6 InvalidDataException (com.intellij.openapi.util.InvalidDataException)5