use of org.apache.oozie.command.CommandException in project oozie by apache.
the class BundleEngine method suspendJobs.
/**
* return a list of suspended Bundle job
*
* @param filter the filter string for which the bundle jobs are suspended
* @param start the starting index for bundle jobs
* @param len maximum number of jobs to be suspended
* @return the list of jobs being suspended
* @throws BundleEngineException thrown if one or more of the jobs cannot be suspended
*/
public BundleJobInfo suspendJobs(String filter, int start, int len) throws BundleEngineException {
try {
Map<String, List<String>> filterList = parseFilter(filter);
BundleJobInfo bundleJobInfo = new BulkBundleXCommand(filterList, start, len, OperationType.Suspend).call();
if (bundleJobInfo == null) {
return new BundleJobInfo(new ArrayList<BundleJobBean>(), 0, 0, 0);
}
return bundleJobInfo;
} catch (CommandException ex) {
throw new BundleEngineException(ex);
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class BundleEngine method change.
/* (non-Javadoc)
* @see org.apache.oozie.BaseEngine#change(java.lang.String, java.lang.String)
*/
@Override
public void change(String jobId, String changeValue) throws BundleEngineException {
try {
BundleJobChangeXCommand change = new BundleJobChangeXCommand(jobId, changeValue);
change.call();
} catch (CommandException ex) {
throw new BundleEngineException(ex);
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class SLAServlet method doGet.
/**
* Return information about SLA Events.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Element eResponse = new Element("sla-message");
List<SLAEventBean> slaEvntList = null;
try {
stopCron();
String gtSequenceNum = request.getParameter(RestConstants.SLA_GT_SEQUENCE_ID);
String strMaxEvents = request.getParameter(RestConstants.MAX_EVENTS);
String filter = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
Map<String, List<String>> filterList = parseFilter(filter, SLA_FILTER_NAMES);
// Default
int maxNoEvents = 100;
XLog.getLog(getClass()).debug("Got SLA GET request for :" + gtSequenceNum + " and max-events :" + strMaxEvents);
if (strMaxEvents != null && strMaxEvents.length() > 0) {
maxNoEvents = Integer.parseInt(strMaxEvents);
}
if (gtSequenceNum != null) {
long seqId = Long.parseLong(gtSequenceNum);
stopCron();
SLAEventsXCommand seCommand = new SLAEventsXCommand(seqId, maxNoEvents, filterList);
slaEvntList = seCommand.call();
long lastSeqId = seCommand.getLastSeqId();
eResponse = new Element("sla-message");
for (SLAEventBean event : slaEvntList) {
eResponse.addContent(event.toXml());
}
Element eLastSeq = new Element("last-sequence-id");
eLastSeq.addContent(String.valueOf(lastSeqId));
eResponse.addContent(eLastSeq);
XLog.getLog(getClass()).debug("Writing back SLA Servlet Caller with last-seq-id " + lastSeqId);
startCron();
} else {
XLog.getLog(getClass()).error("gt-sequence-id parameter is not specified in the http request");
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0401, "gt-sequence-id parameter is not specified in the http request");
}
startCron();
response.setContentType(XML_UTF8);
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(XmlUtils.prettyPrint(eResponse) + "\n");
} catch (CommandException ce) {
ce.printStackTrace();
XLog.getLog(getClass()).error("Command exception ", ce);
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ce);
} catch (RuntimeException re) {
re.printStackTrace();
XLog.getLog(getClass()).error("Runtime error ", re);
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0307, re.getMessage());
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class RecoveryService method mergeConfig.
/**
* Merge Bundle job config and the configuration from the coord job to pass
* to Coord Engine
*
* @param coordElem the coordinator configuration
* @return Configuration merged configuration
* @throws CommandException thrown if failed to merge configuration
*/
private static Configuration mergeConfig(Element coordElem, BundleJobBean bundleJob) throws CommandException {
XLog.Info.get().clear();
XLog log = XLog.getLog("RecoveryService");
String jobConf = bundleJob.getConf();
// Step 1: runConf = jobConf
Configuration runConf = null;
try {
runConf = new XConfiguration(new StringReader(jobConf));
} catch (IOException e1) {
log.warn("Configuration parse error in:" + jobConf);
throw new CommandException(ErrorCode.E1306, e1.getMessage(), e1);
}
// Step 2: Merge local properties into runConf
// extract 'property' tags under 'configuration' block in the coordElem
// convert Element to XConfiguration
Element localConfigElement = coordElem.getChild("configuration", coordElem.getNamespace());
if (localConfigElement != null) {
String strConfig = XmlUtils.prettyPrint(localConfigElement).toString();
Configuration localConf;
try {
localConf = new XConfiguration(new StringReader(strConfig));
} catch (IOException e1) {
log.warn("Configuration parse error in:" + strConfig);
throw new CommandException(ErrorCode.E1307, e1.getMessage(), e1);
}
// copy configuration properties in the coordElem to the runConf
XConfiguration.copy(localConf, runConf);
}
// Step 3: Extract value of 'app-path' in coordElem, save it as a
// new property called 'oozie.coord.application.path', and normalize.
String appPath = coordElem.getChild("app-path", coordElem.getNamespace()).getValue();
runConf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
// Normalize coordinator appPath here;
try {
JobUtils.normalizeAppPath(runConf.get(OozieClient.USER_NAME), runConf.get(OozieClient.GROUP_NAME), runConf);
} catch (IOException e) {
throw new CommandException(ErrorCode.E1001, runConf.get(OozieClient.COORDINATOR_APP_PATH));
}
return runConf;
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class TestCallableQueueService method testRemoveUniqueCallables.
public void testRemoveUniqueCallables() throws Exception {
XCommand command = new XCommand("Test", "type", 100) {
@Override
protected boolean isLockRequired() {
return false;
}
@Override
public String getEntityKey() {
return "TEST";
}
@Override
protected void loadState() throws CommandException {
}
@Override
protected void verifyPrecondition() throws CommandException, PreconditionException {
}
@Override
protected Object execute() throws CommandException {
return null;
}
};
Services.get().destroy();
setSystemProperty(CallableQueueService.CONF_THREADS, "1");
new Services().init();
CallableQueueService queueservice = Services.get().get(CallableQueueService.class);
List<String> uniquesBefore = queueservice.getUniqueDump();
try {
queueservice.queue(command);
fail("Expected illegal argument exception: priority = 100");
} catch (Exception e) {
assertTrue(e.getCause() != null && e.getCause() instanceof IllegalArgumentException);
}
List<String> uniquesAfter = queueservice.getUniqueDump();
uniquesAfter.removeAll(uniquesBefore);
assertTrue(uniquesAfter.toString(), uniquesAfter.isEmpty());
}
Aggregations