Search in sources :

Example 1 with XConfiguration

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

the class BaseJobServlet method doPut.

/**
 * Perform various job related actions - start, suspend, resume, kill, etc.
 */
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String jobId = getResourceName(request);
    request.setAttribute(AUDIT_PARAM, jobId);
    request.setAttribute(AUDIT_OPERATION, request.getParameter(RestConstants.ACTION_PARAM));
    try {
        AuthorizationService auth = Services.get().get(AuthorizationService.class);
        auth.authorizeForJob(getUser(request), jobId, true);
    } catch (AuthorizationException ex) {
        throw new XServletException(HttpServletResponse.SC_UNAUTHORIZED, ex);
    }
    String action = request.getParameter(RestConstants.ACTION_PARAM);
    if (action.equals(RestConstants.JOB_ACTION_START)) {
        stopCron();
        startJob(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.JOB_ACTION_RESUME)) {
        stopCron();
        resumeJob(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.JOB_ACTION_SUSPEND)) {
        stopCron();
        suspendJob(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.JOB_ACTION_KILL)) {
        stopCron();
        JSONObject json = killJob(request, response);
        startCron();
        if (json != null) {
            sendJsonResponse(response, HttpServletResponse.SC_OK, json);
        } else {
            response.setStatus(HttpServletResponse.SC_OK);
        }
    } else if (action.equals(RestConstants.JOB_ACTION_CHANGE)) {
        stopCron();
        changeJob(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.JOB_ACTION_IGNORE)) {
        stopCron();
        JSONObject json = ignoreJob(request, response);
        startCron();
        if (json != null) {
            sendJsonResponse(response, HttpServletResponse.SC_OK, json);
        } else {
            response.setStatus(HttpServletResponse.SC_OK);
        }
    } else if (action.equals(RestConstants.JOB_ACTION_RERUN)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        Configuration conf = new XConfiguration(request.getInputStream());
        stopCron();
        String requestUser = getUser(request);
        if (!requestUser.equals(UNDEF)) {
            conf.set(OozieClient.USER_NAME, requestUser);
        }
        if (conf.get(OozieClient.APP_PATH) != null) {
            BaseJobServlet.checkAuthorizationForApp(conf);
            JobUtils.normalizeAppPath(conf.get(OozieClient.USER_NAME), conf.get(OozieClient.GROUP_NAME), conf);
        }
        reRunJob(request, response, conf);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.JOB_COORD_ACTION_RERUN)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        stopCron();
        JSONObject json = reRunJob(request, response, null);
        startCron();
        if (json != null) {
            sendJsonResponse(response, HttpServletResponse.SC_OK, json);
        } else {
            response.setStatus(HttpServletResponse.SC_OK);
        }
    } else if (action.equals(RestConstants.JOB_BUNDLE_ACTION_RERUN)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        stopCron();
        JSONObject json = reRunJob(request, response, null);
        startCron();
        if (json != null) {
            sendJsonResponse(response, HttpServletResponse.SC_OK, json);
        } else {
            response.setStatus(HttpServletResponse.SC_OK);
        }
    } else if (action.equals(RestConstants.JOB_COORD_UPDATE)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        Configuration conf = new XConfiguration(request.getInputStream());
        stopCron();
        String requestUser = getUser(request);
        if (!requestUser.equals(UNDEF)) {
            conf.set(OozieClient.USER_NAME, requestUser);
        }
        if (conf.get(OozieClient.COORDINATOR_APP_PATH) != null) {
            // If coord is submitted from bundle, user may want to update individual coord job with bundle properties
            // If COORDINATOR_APP_PATH is set, we should check only COORDINATOR_APP_PATH path permission
            String bundlePath = conf.get(OozieClient.BUNDLE_APP_PATH);
            if (bundlePath != null) {
                conf.unset(OozieClient.BUNDLE_APP_PATH);
            }
            BaseJobServlet.checkAuthorizationForApp(conf);
            JobUtils.normalizeAppPath(conf.get(OozieClient.USER_NAME), conf.get(OozieClient.GROUP_NAME), conf);
            if (bundlePath != null) {
                conf.set(OozieClient.BUNDLE_APP_PATH, bundlePath);
            }
        }
        JSONObject json = updateJob(request, response, conf);
        startCron();
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (action.equals(RestConstants.SLA_ENABLE_ALERT)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        stopCron();
        slaEnableAlert(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.SLA_DISABLE_ALERT)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        stopCron();
        slaDisableAlert(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else if (action.equals(RestConstants.SLA_CHANGE)) {
        validateContentType(request, RestConstants.XML_CONTENT_TYPE);
        stopCron();
        slaChange(request, response);
        startCron();
        response.setStatus(HttpServletResponse.SC_OK);
    } else {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303, RestConstants.ACTION_PARAM, action);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) JSONObject(org.json.simple.JSONObject) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) AuthorizationService(org.apache.oozie.service.AuthorizationService) AuthorizationException(org.apache.oozie.service.AuthorizationException)

Example 2 with XConfiguration

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

the class GroupsService method init.

/**
 * Initializes the service.
 *
 * @param services services singleton initializing the service.
 */
@Override
public void init(Services services) {
    Configuration sConf = services.getConf();
    Configuration gConf = new XConfiguration();
    for (Map.Entry<String, String> entry : sConf) {
        String name = entry.getKey();
        if (name.startsWith(CONF_PREFIX)) {
            gConf.set(name.substring(CONF_PREFIX.length()), sConf.get(name));
        }
    }
    hGroups = new org.apache.hadoop.security.Groups(gConf);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Map(java.util.Map)

Example 3 with XConfiguration

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

the class HadoopAccessorService method getConfiguration.

private Configuration getConfiguration(String hostPort) {
    hostPort = (hostPort != null) ? hostPort.toLowerCase() : null;
    Configuration conf = hadoopConfigs.get(hostPort);
    if (conf == null) {
        conf = hadoopConfigs.get("*");
        if (conf == null) {
            conf = new XConfiguration();
        }
    }
    return conf;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration)

Example 4 with XConfiguration

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

the class HadoopAccessorService method loadHadoopConf.

private Configuration loadHadoopConf(File dir) throws IOException {
    Configuration hadoopConf = new XConfiguration();
    for (String file : HADOOP_CONF_FILES) {
        File f = new File(dir, file);
        if (f.exists()) {
            InputStream is = new FileInputStream(f);
            Configuration conf = new XConfiguration(is, false);
            is.close();
            XConfiguration.copy(conf, hadoopConf);
        }
    }
    return hadoopConf;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with XConfiguration

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

the class ConfigurationService method loadConfig.

private XConfiguration loadConfig(InputStream inputStream, boolean defaultConfig) throws IOException, ServiceException {
    XConfiguration configuration;
    configuration = new XConfiguration(inputStream);
    configuration.setRestrictSystemProperties(false);
    for (Map.Entry<String, String> entry : configuration) {
        if (defaultConfig) {
            defaultConfigs.put(entry.getKey(), entry.getValue());
        } else {
            log.debug("Overriding configuration with oozie-site, [{0}]", entry.getKey());
        }
    }
    return configuration;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

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