Search in sources :

Example 11 with XLog

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

the class CoordPushDependencyCheckXCommand method unregisterMissingDependencies.

public static void unregisterMissingDependencies(List<String> missingDeps, String actionId) {
    final XLog LOG = XLog.getLog(CoordPushDependencyCheckXCommand.class);
    URIHandlerService uriService = Services.get().get(URIHandlerService.class);
    for (String missingDep : missingDeps) {
        try {
            URI missingURI = new URI(missingDep);
            URIHandler handler = uriService.getURIHandler(missingURI);
            if (handler.unregisterFromNotification(missingURI, actionId)) {
                LOG.debug("Successfully unregistered uri [{0}] from notifications", missingURI);
            } else {
                LOG.warn("Unable to unregister uri [{0}] from notifications", missingURI);
            }
        } catch (Exception e) {
            LOG.warn("Exception while unregistering uri [{0}] from notifications", missingDep, e);
        }
    }
}
Also used : XLog(org.apache.oozie.util.XLog) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) URI(java.net.URI) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ElException(org.apache.oozie.coord.ElException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 12 with XLog

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

the class SshActionExecutor method doExecute.

/**
 * Execute the ssh command.
 *
 * @param host hostname.
 * @param dirLocation location of the base and wrapper scripts.
 * @param cmnd command to be executed.
 * @param args command arguments.
 * @param ignoreOutput ignore output option.
 * @param action action object.
 * @param recoveryId action id + run number to enable recovery in rerun
 * @param preserveArgs tell the ssh scripts to preserve or flatten the arguments
 * @return processSettings id of the running command.
 * @throws IOException thrown if failed to run the command.
 * @throws InterruptedException thrown if any interruption happens.
 */
protected String doExecute(String host, String dirLocation, String cmnd, String[] args, boolean ignoreOutput, WorkflowAction action, String recoveryId, boolean preserveArgs) throws IOException, InterruptedException {
    XLog log = XLog.getLog(getClass());
    Runtime runtime = Runtime.getRuntime();
    String callbackPost = ignoreOutput ? "_" : ConfigurationService.get(HTTP_COMMAND_OPTIONS).replace(" ", "%%%");
    String preserveArgsS = preserveArgs ? "PRESERVE_ARGS" : "FLATTEN_ARGS";
    // TODO check
    String callBackUrl = Services.get().get(CallbackService.class).createCallBackUrl(action.getId(), EXT_STATUS_VAR);
    String command = XLog.format("{0}{1} {2}ssh-base.sh {3} {4} \"{5}\" \"{6}\" {7} {8} ", SSH_COMMAND_BASE, host, dirLocation, preserveArgsS, ConfigurationService.get(HTTP_COMMAND), callBackUrl, callbackPost, recoveryId, cmnd).toString();
    String[] commandArray = command.split("\\s");
    String[] finalCommand;
    if (args == null) {
        finalCommand = commandArray;
    } else {
        finalCommand = new String[commandArray.length + args.length];
        System.arraycopy(commandArray, 0, finalCommand, 0, commandArray.length);
        System.arraycopy(args, 0, finalCommand, commandArray.length, args.length);
    }
    LOG.trace("Executing SSH command [finalCommand={0}]", Arrays.toString(finalCommand));
    final Process p = runtime.exec(finalCommand);
    final String pid;
    final StringBuffer inputBuffer = new StringBuffer();
    final StringBuffer errorBuffer = new StringBuffer();
    final int exitValue = drainBuffers(p, inputBuffer, errorBuffer, maxLen);
    pid = getFirstLine(inputBuffer);
    String error = null;
    if (exitValue != 0) {
        error = getTruncatedString(errorBuffer);
        throw new IOException(XLog.format("Not able to execute ssh-base.sh on {0}", host) + " | " + "ErrorStream: " + error);
    }
    LOG.trace("After execution pid={0}", pid);
    return pid;
}
Also used : CallbackService(org.apache.oozie.service.CallbackService) XLog(org.apache.oozie.util.XLog) IOException(java.io.IOException)

Example 13 with XLog

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

the class CoordELFunctions method coord_latestRange_sync.

private static String coord_latestRange_sync(int startOffset, int endOffset) throws Exception {
    final XLog LOG = XLog.getLog(CoordELFunctions.class);
    final Thread currentThread = Thread.currentThread();
    ELEvaluator eval = ELEvaluator.getCurrent();
    String retVal = "";
    // in minutes
    int datasetFrequency = (int) getDSFrequency();
    TimeUnit dsTimeUnit = getDSTimeUnit();
    int[] instCount = new int[1];
    boolean useCurrentTime = Services.get().getConf().getBoolean(LATEST_EL_USE_CURRENT_TIME, false);
    Calendar nominalInstanceCal;
    if (useCurrentTime) {
        nominalInstanceCal = getCurrentInstance(new Date(), instCount);
    } else {
        nominalInstanceCal = getCurrentInstance(getActualTime(), instCount);
    }
    StringBuilder resolvedInstances = new StringBuilder();
    StringBuilder resolvedURIPaths = new StringBuilder();
    if (nominalInstanceCal != null) {
        Calendar initInstance = getInitialInstanceCal();
        SyncCoordDataset ds = (SyncCoordDataset) eval.getVariable(DATASET);
        if (ds == null) {
            throw new RuntimeException("Associated Dataset should be defined with key " + DATASET);
        }
        String uriTemplate = ds.getUriTemplate();
        Configuration conf = (Configuration) eval.getVariable(CONFIGURATION);
        if (conf == null) {
            throw new RuntimeException("Associated Configuration should be defined with key " + CONFIGURATION);
        }
        int available = 0;
        boolean resolved = false;
        String user = ParamChecker.notEmpty((String) eval.getVariable(OozieClient.USER_NAME), OozieClient.USER_NAME);
        String doneFlag = ds.getDoneFlag();
        URIHandlerService uriService = Services.get().get(URIHandlerService.class);
        URIHandler uriHandler = null;
        Context uriContext = null;
        try {
            while (nominalInstanceCal.compareTo(initInstance) >= 0 && !currentThread.isInterrupted()) {
                ELEvaluator uriEval = getUriEvaluator(nominalInstanceCal);
                String uriPath = uriEval.evaluate(uriTemplate, String.class);
                if (uriHandler == null) {
                    URI uri = new URI(uriPath);
                    uriHandler = uriService.getURIHandler(uri);
                    uriContext = uriHandler.getContext(uri, conf, user, true);
                }
                String uriWithDoneFlag = uriHandler.getURIWithDoneFlag(uriPath, doneFlag);
                if (uriHandler.exists(new URI(uriWithDoneFlag), uriContext)) {
                    XLog.getLog(CoordELFunctions.class).debug("Found latest(" + available + "): " + uriWithDoneFlag);
                    if (available == startOffset) {
                        LOG.debug("Matched latest(" + available + "): " + uriWithDoneFlag);
                        resolved = true;
                        resolvedInstances.append(DateUtils.formatDateOozieTZ(nominalInstanceCal));
                        resolvedURIPaths.append(uriPath);
                        retVal = resolvedInstances.toString();
                        eval.setVariable(CoordELConstants.RESOLVED_PATH, resolvedURIPaths.toString());
                        break;
                    } else if (available <= endOffset) {
                        LOG.debug("Matched latest(" + available + "): " + uriWithDoneFlag);
                        resolvedInstances.append(DateUtils.formatDateOozieTZ(nominalInstanceCal)).append(INSTANCE_SEPARATOR);
                        resolvedURIPaths.append(uriPath).append(INSTANCE_SEPARATOR);
                    }
                    available--;
                }
                // nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), -datasetFrequency);
                nominalInstanceCal = (Calendar) initInstance.clone();
                instCount[0]--;
                nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), instCount[0] * datasetFrequency);
            // DateUtils.moveToEnd(nominalInstanceCal, getDSEndOfFlag());
            }
            if (!StringUtils.isEmpty(resolvedURIPaths.toString()) && eval.getVariable(CoordELConstants.RESOLVED_PATH) == null) {
                eval.setVariable(CoordELConstants.RESOLVED_PATH, resolvedURIPaths.toString());
            }
        } finally {
            if (uriContext != null) {
                uriContext.destroy();
            }
        }
        if (!resolved) {
            // return unchanged latest function with variable 'is_resolved'
            // to 'false'
            eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE);
            if (startOffset == endOffset) {
                retVal = "${coord:latest(" + startOffset + ")}";
            } else {
                retVal = "${coord:latestRange(" + startOffset + "," + endOffset + ")}";
            }
        } else {
            eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.TRUE);
        }
    } else {
        // No feasible nominal time
        eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE);
    }
    return retVal;
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) Configuration(org.apache.hadoop.conf.Configuration) XLog(org.apache.oozie.util.XLog) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) URI(java.net.URI) Date(java.util.Date) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 14 with XLog

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

the class DependencyChecker method checkForAvailability.

/**
 * Get the currently missing and available dependencies after checking the list of known missing
 * dependencies against the source.
 *
 * @param missingDependencies known missing dependencies
 * @param actionConf Configuration for the action
 * @param stopOnFirstMissing Does not continue check for the rest of list if there is a missing
 *        dependency
 * @return ActionDependency which has the list of missing and available dependencies
 * @throws CommandException in case of error
 */
public static ActionDependency checkForAvailability(List<String> missingDependencies, Configuration actionConf, boolean stopOnFirstMissing) throws CommandException {
    // OOZIE-1251. Don't initialize as static variable.
    final XLog LOG = XLog.getLog(DependencyChecker.class);
    String user = ParamChecker.notEmpty(actionConf.get(OozieClient.USER_NAME), OozieClient.USER_NAME);
    List<String> missingDeps = new ArrayList<String>();
    List<String> availableDeps = new ArrayList<String>();
    URIHandlerService uriService = Services.get().get(URIHandlerService.class);
    boolean continueChecking = true;
    try {
        for (int index = 0; index < missingDependencies.size(); index++) {
            if (continueChecking) {
                String dependency = missingDependencies.get(index);
                URI uri = new URI(dependency);
                URIHandler uriHandler = uriService.getURIHandler(uri);
                LOG.debug("Checking for the availability of dependency [{0}] ", dependency);
                if (uriHandler.exists(uri, actionConf, user)) {
                    LOG.debug("Dependency [{0}] is available", dependency);
                    availableDeps.add(dependency);
                } else {
                    LOG.debug("Dependency [{0}] is missing", dependency);
                    missingDeps.add(dependency);
                    if (stopOnFirstMissing) {
                        continueChecking = false;
                    }
                }
            } else {
                missingDeps.add(missingDependencies.get(index));
            }
        }
    } catch (URISyntaxException e) {
        throw new CommandException(ErrorCode.E0906, e.getMessage(), e);
    } catch (URIHandlerException e) {
        throw new CommandException(e);
    }
    return new ActionDependency(missingDeps, availableDeps);
}
Also used : XLog(org.apache.oozie.util.XLog) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) CommandException(org.apache.oozie.command.CommandException) URI(java.net.URI) URIHandlerService(org.apache.oozie.service.URIHandlerService)

Example 15 with XLog

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

the class HCatELFunctions method getURIFromResolved.

private static HCatURI getURIFromResolved(String dataInName, EventType type) {
    final XLog LOG = XLog.getLog(HCatELFunctions.class);
    StringBuilder uriTemplate = new StringBuilder();
    ELEvaluator eval = ELEvaluator.getCurrent();
    String uris;
    if (type == EventType.input) {
        uris = (String) eval.getVariable(".datain." + dataInName);
    } else {
        // type=output
        uris = (String) eval.getVariable(".dataout." + dataInName);
    }
    if (uris != null) {
        String[] uri = HCatURIParser.splitHCatUris(uris, HCAT_URI_PATTERN);
        uriTemplate.append(uri[0]);
    } else {
        LOG.warn("URI is NULL");
        return null;
    }
    LOG.info("uriTemplate [{0}] ", uriTemplate);
    HCatURI hcatURI;
    try {
        hcatURI = new HCatURI(uriTemplate.toString());
    } catch (URISyntaxException e) {
        LOG.info("uriTemplate [{0}]. Reason [{1}]: ", uriTemplate, e);
        throw new RuntimeException("HCat URI can't be parsed " + e);
    }
    return hcatURI;
}
Also used : XLog(org.apache.oozie.util.XLog) URISyntaxException(java.net.URISyntaxException) ELEvaluator(org.apache.oozie.util.ELEvaluator) HCatURI(org.apache.oozie.util.HCatURI)

Aggregations

XLog (org.apache.oozie.util.XLog)21 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)5 URI (java.net.URI)4 URIHandlerService (org.apache.oozie.service.URIHandlerService)4 File (java.io.File)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Configuration (org.apache.hadoop.conf.Configuration)3 CommandException (org.apache.oozie.command.CommandException)3 URIHandler (org.apache.oozie.dependency.URIHandler)3 ELEvaluator (org.apache.oozie.util.ELEvaluator)3 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 Context (org.apache.oozie.dependency.URIHandler.Context)2 Instrumentation (org.apache.oozie.util.Instrumentation)2 WorkflowException (org.apache.oozie.workflow.WorkflowException)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 StringReader (java.io.StringReader)1