Search in sources :

Example 21 with Namespace

use of org.osate.aadl2.Namespace in project oozie by apache.

the class EmailActionExecutor method validateAndMail.

@SuppressWarnings("unchecked")
protected void validateAndMail(Context context, Element element) throws ActionExecutorException {
    // The XSD does the min/max occurrence validation for us.
    Namespace ns = element.getNamespace();
    String[] tos = new String[0];
    String[] ccs = new String[0];
    String[] bccs;
    String subject = "";
    String body = "";
    String[] attachments = new String[0];
    String contentType;
    Element child = null;
    // <to> - One ought to exist.
    String text = element.getChildTextTrim(TO, ns);
    if (text.isEmpty()) {
        throw new ActionExecutorException(ErrorType.ERROR, "EM001", "No recipients were specified in the to-address field.");
    }
    tos = text.split(COMMA);
    // <cc> - Optional, but only one ought to exist.
    try {
        ccs = element.getChildTextTrim(CC, ns).split(COMMA);
    } catch (Exception e) {
        // It is alright for cc to be given empty or not be present.
        ccs = new String[0];
    }
    // <bcc> - Optional, but only one ought to exist.
    try {
        bccs = element.getChildTextTrim(BCC, ns).split(COMMA);
    } catch (Exception e) {
        // It is alright for bcc to be given empty or not be present.
        bccs = new String[0];
    }
    // <subject> - One ought to exist.
    subject = element.getChildTextTrim(SUB, ns);
    // <body> - One ought to exist.
    body = element.getChildTextTrim(BOD, ns);
    // <attachment> - Optional
    String attachment = element.getChildTextTrim(ATTACHMENT, ns);
    if (attachment != null) {
        attachments = attachment.split(COMMA);
    }
    contentType = element.getChildTextTrim(CONTENT_TYPE, ns);
    if (contentType == null || contentType.isEmpty()) {
        contentType = DEFAULT_CONTENT_TYPE;
    }
    // All good - lets try to mail!
    email(tos, ccs, bccs, subject, body, attachments, contentType, context.getWorkflow().getUser());
}
Also used : Element(org.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Namespace(org.jdom2.Namespace) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) NoSuchProviderException(javax.mail.NoSuchProviderException)

Example 22 with Namespace

use of org.osate.aadl2.Namespace in project oozie by apache.

the class SubmitHttpXCommand method getWorkflowXml.

/**
 * Generate workflow xml from conf object
 *
 * @param conf the configuration object
 * @return workflow xml def string representation
 */
protected String getWorkflowXml(Configuration conf) {
    checkMandatoryConf(conf);
    Namespace ns = getWorkflowNamespace();
    Element root = new Element("workflow-app", ns);
    String name = getWorkflowName();
    root.setAttribute("name", "oozie-" + name);
    Element start = new Element("start", ns);
    String nodeName = name + "1";
    start.setAttribute("to", nodeName);
    root.addContent(start);
    Element action = new Element("action", ns);
    action.setAttribute("name", nodeName);
    Element ele = generateSection(conf, getSectionNamespace());
    action.addContent(ele);
    Element ok = new Element("ok", ns);
    ok.setAttribute("to", "end");
    action.addContent(ok);
    Element error = new Element("error", ns);
    error.setAttribute("to", "fail");
    action.addContent(error);
    root.addContent(action);
    Element kill = new Element("kill", ns);
    kill.setAttribute("name", "fail");
    Element message = new Element("message", ns);
    message.addContent(name + " failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
    kill.addContent(message);
    root.addContent(kill);
    Element end = new Element("end", ns);
    end.setAttribute("name", "end");
    root.addContent(end);
    return XmlUtils.prettyPrint(root).toString();
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 23 with Namespace

use of org.osate.aadl2.Namespace in project oozie by apache.

the class CoordSubmitXCommand method checkMultipleTimeInstances.

/*
  * Check against multiple data instance values inside a single <instance> <start-instance> or <end-instance> tag
  * If found, the job is not submitted and user is informed to correct the error,
  *  instead of defaulting to the first instance value in the list
  */
private void checkMultipleTimeInstances(Element eCoordJob, String eventType, String dataType) throws CoordinatorJobException {
    Element eventsSpec, dataSpec, instance;
    List<Element> instanceSpecList;
    Namespace ns = eCoordJob.getNamespace();
    String instanceValue;
    eventsSpec = eCoordJob.getChild(eventType, ns);
    if (eventsSpec != null) {
        dataSpec = eventsSpec.getChild(dataType, ns);
        if (dataSpec != null) {
            // In case of input-events, there can be multiple child <instance> datasets.
            // Iterating to ensure none of them have errors
            instanceSpecList = dataSpec.getChildren("instance", ns);
            Iterator instanceIter = instanceSpecList.iterator();
            while (instanceIter.hasNext()) {
                instance = ((Element) instanceIter.next());
                if (instance.getContentSize() == 0) {
                    // empty string or whitespace
                    throw new CoordinatorJobException(ErrorCode.E1021, "<instance> tag within " + eventType + " is empty!");
                }
                instanceValue = instance.getContent(0).toString();
                boolean isInvalid = false;
                try {
                    isInvalid = StringUtils.checkStaticExistence(instanceValue, ",");
                } catch (Exception e) {
                    handleELParseException(eventType, dataType, instanceValue);
                }
                if (isInvalid) {
                    // reaching this block implies instance is not empty i.e. length > 0
                    handleExpresionWithMultipleInstances(eventType, dataType, instanceValue);
                }
            }
            // In case of input-events, there can be multiple child <start-instance> datasets.
            // Iterating to ensure none of them have errors
            instanceSpecList = dataSpec.getChildren("start-instance", ns);
            instanceIter = instanceSpecList.iterator();
            while (instanceIter.hasNext()) {
                instance = ((Element) instanceIter.next());
                if (instance.getContentSize() == 0) {
                    // empty string or whitespace
                    throw new CoordinatorJobException(ErrorCode.E1021, "<start-instance> tag within " + eventType + " is empty!");
                }
                instanceValue = instance.getContent(0).toString();
                boolean isInvalid = false;
                try {
                    isInvalid = StringUtils.checkStaticExistence(instanceValue, ",");
                } catch (Exception e) {
                    handleELParseException(eventType, dataType, instanceValue);
                }
                if (isInvalid) {
                    // reaching this block implies start instance is not empty i.e. length > 0
                    handleExpresionWithStartMultipleInstances(eventType, dataType, instanceValue);
                }
            }
            // In case of input-events, there can be multiple child <end-instance> datasets.
            // Iterating to ensure none of them have errors
            instanceSpecList = dataSpec.getChildren("end-instance", ns);
            instanceIter = instanceSpecList.iterator();
            while (instanceIter.hasNext()) {
                instance = ((Element) instanceIter.next());
                if (instance.getContentSize() == 0) {
                    // empty string or whitespace
                    throw new CoordinatorJobException(ErrorCode.E1021, "<end-instance> tag within " + eventType + " is empty!");
                }
                instanceValue = instance.getContent(0).toString();
                boolean isInvalid = false;
                try {
                    isInvalid = StringUtils.checkStaticExistence(instanceValue, ",");
                } catch (Exception e) {
                    handleELParseException(eventType, dataType, instanceValue);
                }
                if (isInvalid) {
                    // reaching this block implies instance is not empty i.e. length > 0
                    handleExpresionWithMultipleEndInstances(eventType, dataType, instanceValue);
                }
            }
        }
    }
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Element(org.jdom2.Element) Iterator(java.util.Iterator) Namespace(org.jdom2.Namespace) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom2.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException)

Example 24 with Namespace

use of org.osate.aadl2.Namespace in project oozie by apache.

the class JavaActionExecutor method parseJobXmlAndConfiguration.

public static void parseJobXmlAndConfiguration(Context context, Element element, Path appPath, Configuration conf, boolean isLauncher) throws IOException, ActionExecutorException, HadoopAccessorException, URISyntaxException {
    Namespace ns = element.getNamespace();
    @SuppressWarnings("unchecked") Iterator<Element> it = element.getChildren("job-xml", ns).iterator();
    HashMap<String, FileSystem> filesystemsMap = new HashMap<String, FileSystem>();
    HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
    while (it.hasNext()) {
        Element e = it.next();
        String jobXml = e.getTextTrim();
        Path pathSpecified = new Path(jobXml);
        Path path = pathSpecified.isAbsolute() ? pathSpecified : new Path(appPath, jobXml);
        FileSystem fs;
        if (filesystemsMap.containsKey(path.toUri().getAuthority())) {
            fs = filesystemsMap.get(path.toUri().getAuthority());
        } else {
            if (path.toUri().getAuthority() != null) {
                fs = has.createFileSystem(context.getWorkflow().getUser(), path.toUri(), has.createConfiguration(path.toUri().getAuthority()));
            } else {
                fs = context.getAppFileSystem();
            }
            filesystemsMap.put(path.toUri().getAuthority(), fs);
        }
        Configuration jobXmlConf = new XConfiguration(fs.open(path));
        try {
            String jobXmlConfString = XmlUtils.prettyPrint(jobXmlConf).toString();
            jobXmlConfString = XmlUtils.removeComments(jobXmlConfString);
            jobXmlConfString = context.getELEvaluator().evaluate(jobXmlConfString, String.class);
            jobXmlConf = new XConfiguration(new StringReader(jobXmlConfString));
        } catch (ELEvaluationException ex) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, "EL_EVAL_ERROR", ex.getMessage(), ex);
        } catch (Exception ex) {
            context.setErrorInfo("EL_ERROR", ex.getMessage());
        }
        checkForDisallowedProps(jobXmlConf, "job-xml");
        if (isLauncher) {
            new LauncherConfigurationInjector(jobXmlConf).inject(conf);
        } else {
            XConfiguration.copy(jobXmlConf, conf);
        }
    }
    Element e = element.getChild("configuration", ns);
    if (e != null) {
        String strConf = XmlUtils.prettyPrint(e).toString();
        XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
        checkForDisallowedProps(inlineConf, "inline configuration");
        if (isLauncher) {
            new LauncherConfigurationInjector(inlineConf).inject(conf);
        } else {
            XConfiguration.copy(inlineConf, conf);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Element(org.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) Namespace(org.jdom2.Namespace) JDOMException(org.jdom2.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) RemoteException(org.apache.hadoop.ipc.RemoteException) AccessControlException(org.apache.hadoop.security.AccessControlException) XConfiguration(org.apache.oozie.util.XConfiguration) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) FileSystem(org.apache.hadoop.fs.FileSystem) StringReader(java.io.StringReader)

Example 25 with Namespace

use of org.osate.aadl2.Namespace in project oozie by apache.

the class JavaActionExecutor method setupLauncherConf.

Configuration setupLauncherConf(Configuration conf, Element actionXml, Path appPath, Context context) throws ActionExecutorException {
    try {
        Namespace ns = actionXml.getNamespace();
        XConfiguration launcherConf = new XConfiguration();
        // Inject action defaults for launcher
        HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
        XConfiguration actionDefaultConf = has.createActionDefaultConf(conf.get(HADOOP_YARN_RM), getType());
        new LauncherConfigurationInjector(actionDefaultConf).inject(launcherConf);
        // Inject <job-xml> and <configuration> for launcher
        try {
            parseJobXmlAndConfiguration(context, actionXml, appPath, launcherConf, true);
        } catch (HadoopAccessorException ex) {
            throw convertException(ex);
        } catch (URISyntaxException ex) {
            throw convertException(ex);
        }
        XConfiguration.copy(launcherConf, conf);
        // Inject config-class for launcher to use for action
        Element e = actionXml.getChild("config-class", ns);
        if (e != null) {
            conf.set(LauncherAMUtils.OOZIE_ACTION_CONFIG_CLASS, e.getTextTrim());
        }
        checkForDisallowedProps(launcherConf, "launcher configuration");
        return conf;
    } catch (IOException ex) {
        throw convertException(ex);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom2.Element) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) Namespace(org.jdom2.Namespace)

Aggregations

Namespace (org.jdom2.Namespace)151 Element (org.jdom2.Element)123 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)21 List (java.util.List)21 Document (org.jdom2.Document)21 XConfiguration (org.apache.oozie.util.XConfiguration)19 Attribute (org.jdom2.Attribute)17 Configuration (org.apache.hadoop.conf.Configuration)15 StringReader (java.io.StringReader)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 Namespace.getNamespace (org.jdom2.Namespace.getNamespace)14 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)13 Map (java.util.Map)12 Path (org.apache.hadoop.fs.Path)12 JDOMException (org.jdom2.JDOMException)12 SAXBuilder (org.jdom2.input.SAXBuilder)11 File (java.io.File)10 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)9