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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations