Search in sources :

Example 91 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class CoordActionNotificationXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    Configuration conf;
    try {
        conf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    } catch (IOException e1) {
        LOG.warn("Configuration parse error. read from DB :" + actionBean.getRunConf());
        throw new CommandException(ErrorCode.E1005, e1.getMessage(), e1);
    }
    url = conf.get(OozieClient.COORD_ACTION_NOTIFICATION_URL);
    if (url != null) {
        url = url.replaceAll(ACTION_ID_PATTERN, actionBean.getId());
        url = url.replaceAll(STATUS_PATTERN, actionBean.getStatus().toString());
        proxyConf = conf.get(OozieClient.COORD_ACTION_NOTIFICATION_PROXY, Services.get().getConf().get(NOTIFICATION_PROXY_KEY));
        LOG.debug("Proxy :" + proxyConf);
    }
    LOG.debug("Notification URL :" + url);
    LogUtils.setLogInfo(actionBean);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 92 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class CoordCommandUtils method dryRunCoord.

/**
 * @param eAction the actionXml related element
 * @param actionBean the coordinator action bean
 * @return actionXml returns actionXml as String
 * @throws Exception
 */
static String dryRunCoord(Element eAction, CoordinatorActionBean actionBean) throws Exception {
    String action = XmlUtils.prettyPrint(eAction).toString();
    StringBuilder actionXml = new StringBuilder(action);
    Configuration actionConf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    actionBean.setActionXml(action);
    if (CoordUtils.isInputLogicSpecified(eAction)) {
        new CoordInputLogicEvaluatorUtil(actionBean).validateInputLogic();
    }
    boolean isPushDepAvailable = true;
    String pushMissingDependencies = actionBean.getPushInputDependencies().getMissingDependencies();
    if (pushMissingDependencies != null) {
        ActionDependency actionDependencies = DependencyChecker.checkForAvailability(pushMissingDependencies, actionConf, true);
        if (actionDependencies.getMissingDependencies().size() != 0) {
            isPushDepAvailable = false;
        }
    }
    boolean isPullDepAvailable = true;
    CoordActionInputCheckXCommand coordActionInput = new CoordActionInputCheckXCommand(actionBean.getId(), actionBean.getJobId());
    if (actionBean.getMissingDependencies() != null) {
        StringBuilder existList = new StringBuilder();
        StringBuilder nonExistList = new StringBuilder();
        StringBuilder nonResolvedList = new StringBuilder();
        getResolvedList(actionBean.getPullInputDependencies().getMissingDependencies(), nonExistList, nonResolvedList);
        isPullDepAvailable = actionBean.getPullInputDependencies().checkPullMissingDependencies(actionBean, existList, nonExistList);
    }
    if (isPullDepAvailable && isPushDepAvailable) {
        // Check for latest/future
        boolean isLatestFutureDepAvailable = coordActionInput.checkUnResolvedInput(actionBean, actionXml, actionConf);
        if (isLatestFutureDepAvailable) {
            String newActionXml = CoordActionInputCheckXCommand.resolveCoordConfiguration(actionXml, actionConf, actionBean.getId());
            actionXml.replace(0, actionXml.length(), newActionXml);
        }
    }
    return actionXml.toString();
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordInputLogicEvaluatorUtil(org.apache.oozie.coord.input.logic.CoordInputLogicEvaluatorUtil) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StringReader(java.io.StringReader) ActionDependency(org.apache.oozie.dependency.ActionDependency)

Example 93 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class ReRunXCommand method setupReRun.

private void setupReRun() throws CommandException {
    InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
    LogUtils.setLogInfo(wfBean);
    WorkflowInstance oldWfInstance = this.wfBean.getWorkflowInstance();
    WorkflowInstance newWfInstance;
    String appPath = null;
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    try {
        XLog.Info.get().setParameter(DagXLogInfoService.TOKEN, conf.get(OozieClient.LOG_TOKEN));
        WorkflowApp app = wps.parseDef(conf, null);
        XConfiguration protoActionConf = wps.createProtoActionConf(conf, true);
        WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
        appPath = conf.get(OozieClient.APP_PATH);
        URI uri = new URI(appPath);
        HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
        Configuration fsConf = has.createConfiguration(uri.getAuthority());
        FileSystem fs = has.createFileSystem(wfBean.getUser(), uri, fsConf);
        Path configDefault = null;
        // app path could be a directory
        Path path = new Path(uri.getPath());
        if (!fs.isFile(path)) {
            configDefault = new Path(path, SubmitXCommand.CONFIG_DEFAULT);
        } else {
            configDefault = new Path(path.getParent(), SubmitXCommand.CONFIG_DEFAULT);
        }
        if (fs.exists(configDefault)) {
            Configuration defaultConf = new XConfiguration(fs.open(configDefault));
            PropertiesUtils.checkDisallowedProperties(defaultConf, DISALLOWED_DEFAULT_PROPERTIES);
            XConfiguration.injectDefaults(defaultConf, conf);
        }
        PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);
        // Resolving all variables in the job properties. This ensures the Hadoop Configuration semantics are
        // preserved. The Configuration.get function within XConfiguration.resolve() works recursively to get the
        // final value corresponding to a key in the map Resetting the conf to contain all the resolved values is
        // necessary to ensure propagation of Oozie properties to Hadoop calls downstream
        conf = ((XConfiguration) conf).resolve();
        try {
            newWfInstance = workflowLib.createInstance(app, conf, jobId);
        } catch (WorkflowException e) {
            throw new CommandException(e);
        }
        String appName = ELUtils.resolveAppName(app.getName(), conf);
        if (SLAService.isEnabled()) {
            Element wfElem = XmlUtils.parseXml(app.getDefinition());
            ELEvaluator evalSla = SubmitXCommand.createELEvaluatorForGroup(conf, "wf-sla-submit");
            Element eSla = XmlUtils.getSLAElement(wfElem);
            String jobSlaXml = null;
            if (eSla != null) {
                jobSlaXml = SubmitXCommand.resolveSla(eSla, evalSla);
            }
            writeSLARegistration(wfElem, jobSlaXml, newWfInstance.getId(), conf.get(SubWorkflowActionExecutor.PARENT_ID), conf.get(OozieClient.USER_NAME), appName, evalSla);
        }
        wfBean.setAppName(appName);
        wfBean.setProtoActionConf(protoActionConf.toXmlString());
    } catch (WorkflowException ex) {
        throw new CommandException(ex);
    } catch (IOException ex) {
        throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
    } catch (HadoopAccessorException ex) {
        throw new CommandException(ex);
    } catch (URISyntaxException ex) {
        throw new CommandException(ErrorCode.E0711, appPath, ex.getMessage(), ex);
    } catch (Exception ex) {
        throw new CommandException(ErrorCode.E1007, ex.getMessage(), ex);
    }
    for (int i = 0; i < actions.size(); i++) {
        // action will be used to rerun the job.
        if (!nodesToSkip.contains(actions.get(i).getName()) && !(conf.getBoolean(OozieClient.RERUN_FAIL_NODES, false) && SubWorkflowActionExecutor.ACTION_TYPE.equals(actions.get(i).getType()))) {
            deleteList.add(actions.get(i));
            LOG.info("Deleting Action[{0}] for re-run", actions.get(i).getId());
        } else {
            copyActionData(newWfInstance, oldWfInstance);
        }
    }
    wfBean.setAppPath(conf.get(OozieClient.APP_PATH));
    wfBean.setConf(XmlUtils.prettyPrint(conf).toString());
    wfBean.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
    wfBean.setUser(conf.get(OozieClient.USER_NAME));
    String group = ConfigUtils.getWithDeprecatedCheck(conf, OozieClient.JOB_ACL, OozieClient.GROUP_NAME, null);
    wfBean.setGroup(group);
    wfBean.setExternalId(conf.get(OozieClient.EXTERNAL_ID));
    wfBean.setEndTime(null);
    wfBean.setRun(wfBean.getRun() + 1);
    wfBean.setStatus(WorkflowJob.Status.PREP);
    wfBean.setWorkflowInstance(newWfInstance);
    try {
        wfBean.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_RERUN, wfBean));
        // call JPAExecutor to do the bulk writes
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, deleteList);
    } catch (JPAExecutorException je) {
        throw new CommandException(je);
    } finally {
        updateParentIfNecessary(wfBean);
    }
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) URISyntaxException(java.net.URISyntaxException) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) URI(java.net.URI) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) FileSystem(org.apache.hadoop.fs.FileSystem) ELEvaluator(org.apache.oozie.util.ELEvaluator) Path(org.apache.hadoop.fs.Path) WorkflowLib(org.apache.oozie.workflow.WorkflowLib) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) WorkflowException(org.apache.oozie.workflow.WorkflowException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) IOException(java.io.IOException) WorkflowException(org.apache.oozie.workflow.WorkflowException) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)

Example 94 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class SignalXCommand method createSLARegistrationForAllActions.

@SuppressWarnings("unchecked")
private void createSLARegistrationForAllActions(String wfXml, String user, String group, String strConf) throws CommandException {
    try {
        Element eWfJob = XmlUtils.parseXml(wfXml);
        Configuration conf = new XConfiguration(new StringReader(strConf));
        for (Element action : (List<Element>) eWfJob.getChildren("action", eWfJob.getNamespace())) {
            Element eSla = XmlUtils.getSLAElement(action);
            if (eSla != null) {
                String slaXml = resolveSla(eSla, conf);
                eSla = XmlUtils.parseXml(slaXml);
                String actionId = Services.get().get(UUIDService.class).generateChildId(jobId, action.getAttributeValue("name") + "");
                SLAEventBean slaEvent = SLADbXOperations.createSlaRegistrationEvent(eSla, actionId, SlaAppType.WORKFLOW_ACTION, user, group);
                if (slaEvent != null) {
                    insertList.add(slaEvent);
                }
            }
        }
    } catch (Exception e) {
        throw new CommandException(ErrorCode.E1007, "workflow:Actions " + jobId, e.getMessage(), e);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) StringReader(java.io.StringReader) List(java.util.List) ArrayList(java.util.ArrayList) UUIDService(org.apache.oozie.service.UUIDService) CommandException(org.apache.oozie.command.CommandException) SLAEventBean(org.apache.oozie.SLAEventBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) IOException(java.io.IOException) XException(org.apache.oozie.XException) WorkflowException(org.apache.oozie.workflow.WorkflowException)

Example 95 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class CoordRerunXCommand method updateAction.

/**
 * Update an action into database table
 *
 * @param coordJob coordinator job bean
 * @param coordAction coordinator action bean
 * @throws Exception thrown failed to update coordinator action bean or unable to write sla registration event
 */
private void updateAction(CoordinatorJobBean coordJob, CoordinatorActionBean coordAction) throws Exception {
    LOG.debug("updateAction for actionId=" + coordAction.getId());
    if (coordAction.getStatus() == CoordinatorAction.Status.TIMEDOUT) {
        LOG.debug("Updating created time for TIMEDOUT action id =" + coordAction.getId());
        coordAction.setCreatedTime(new Date());
    }
    coordAction.setStatus(CoordinatorAction.Status.WAITING);
    if (!failed) {
        coordAction.setExternalId(null);
    }
    coordAction.setExternalStatus(null);
    coordAction.setRerunTime(new Date());
    coordAction.setLastModifiedTime(new Date());
    coordAction.setErrorCode("");
    coordAction.setErrorMessage("");
    // Pushing the configuration which passed through rerun.
    if (actionRunConf != null && actionRunConf.size() > 0) {
        Configuration createdConf = null;
        if (coordAction.getCreatedConf() != null) {
            createdConf = new XConfiguration(new StringReader(coordAction.getCreatedConf()));
        } else {
            createdConf = new Configuration();
        }
        createdConf.set(RERUN_CONF, XmlUtils.prettyPrint(actionRunConf).toString());
        coordAction.setCreatedConf(XmlUtils.prettyPrint(createdConf).toString());
    }
    updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_RERUN, coordAction));
    writeActionRegistration(coordAction.getActionXml(), coordAction, coordJob.getUser(), coordJob.getGroup());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) Date(java.util.Date) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Aggregations

XConfiguration (org.apache.oozie.util.XConfiguration)373 Configuration (org.apache.hadoop.conf.Configuration)241 Path (org.apache.hadoop.fs.Path)106 StringReader (java.io.StringReader)97 File (java.io.File)92 IOException (java.io.IOException)78 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)75 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)70 CommandException (org.apache.oozie.command.CommandException)68 Element (org.jdom.Element)66 Writer (java.io.Writer)58 Date (java.util.Date)50 FileSystem (org.apache.hadoop.fs.FileSystem)48 FileWriter (java.io.FileWriter)45 Reader (java.io.Reader)43 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)37 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)28 OutputStream (java.io.OutputStream)27 FileOutputStream (java.io.FileOutputStream)25