use of org.apache.oozie.store.StoreException in project oozie by apache.
the class TestCoordChangeXCommand method testCoordChangeXCommand.
/**
* Testing the Coordinator Change Commands with different combination of
* "Change Value"
* Changing the end time to be 20 minutes after the current time
* Changing the pause time to be 10 minutes after the current time
*
* @throws Exception
*/
public void testCoordChangeXCommand() throws StoreException, CommandException {
System.out.println("Running Test");
String jobId = "0000000-" + new Date().getTime() + "-testCoordChangeXCommand-C";
try {
addRecordToJobTable(jobId);
} catch (Exception ex) {
ex.printStackTrace();
fail("Exception thrown " + ex);
}
String pauseTime = convertDateToString(new Date().getTime() + 10 * 60 * 1000);
String endTime = convertDateToString(new Date().getTime() + 20 * 60 * 1000);
new CoordChangeXCommand(jobId, "endtime=" + endTime + ";concurrency=200").call();
try {
checkCoordJobs(jobId, DateUtils.parseDateOozieTZ(endTime), 200, null, false);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
String changeValue = "endtime=" + endTime + ";concurrency=200;pausetime=" + pauseTime;
new CoordChangeXCommand(jobId, changeValue).call();
try {
checkCoordJobs(jobId, DateUtils.parseDateOozieTZ(endTime), 200, DateUtils.parseDateOozieTZ(pauseTime), true);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
new CoordChangeXCommand(jobId, "endtime=" + endTime + ";concurrency=200;pausetime=").call();
try {
checkCoordJobs(jobId, DateUtils.parseDateOozieTZ(endTime), 200, null, true);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
new CoordChangeXCommand(jobId, "endtime=" + endTime + ";pausetime=;concurrency=200").call();
try {
checkCoordJobs(jobId, DateUtils.parseDateOozieTZ(endTime), 200, null, true);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
new CoordChangeXCommand(jobId, "endtime=2012-12-20T05:00Z;concurrency=-200").call();
try {
checkCoordJobs(jobId, DateUtils.parseDateOozieTZ("2012-12-20T05:00Z"), -200, null, false);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
new CoordChangeXCommand(jobId, "endtime=2012-12-20T05:00Z").call();
try {
checkCoordJobs(jobId, DateUtils.parseDateOozieTZ("2012-12-20T05:00Z"), null, null, false);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
new CoordChangeXCommand(jobId, "concurrency=-1").call();
try {
checkCoordJobs(jobId, null, -1, null, false);
} catch (Exception ex) {
ex.printStackTrace();
fail("Invalid date" + ex);
}
try {
new CoordChangeXCommand(jobId, "a=1;b=-200").call();
fail("Should not reach here.");
} catch (CommandException ex) {
if (ex.getErrorCode() != ErrorCode.E1015) {
fail("Error code should be E1015.");
}
}
try {
new CoordChangeXCommand(jobId, "endtime=2012-12-20T05:00;concurrency=-200").call();
fail("Should not reach here.");
} catch (CommandException ex) {
if (ex.getErrorCode() != ErrorCode.E1015) {
fail("Error code should be E1015.");
}
}
try {
new CoordChangeXCommand(jobId, "endtime=2012-12-20T05:00Z;concurrency=2ac").call();
fail("Should not reach here.");
} catch (CommandException ex) {
if (ex.getErrorCode() != ErrorCode.E1015) {
fail("Error code should be E1015.");
}
}
try {
new CoordChangeXCommand(jobId, "endtime=1900-12-20T05:00Z").call();
} catch (CommandException ex) {
fail("Should not throw exception");
}
try {
new CoordChangeXCommand(jobId, "pausetime=null").call();
fail("Should not reach here.");
} catch (CommandException ex) {
if (ex.getErrorCode() != ErrorCode.E1015) {
fail("Error code should be E1015.");
}
}
try {
new CoordChangeXCommand(jobId, "pausetime=" + pauseTime).call();
} catch (CommandException ex) {
fail("Should not throw exception");
}
}
use of org.apache.oozie.store.StoreException in project oozie by apache.
the class SubmitXCommand method execute.
@Override
protected String execute() throws CommandException {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
try {
XLog.Info.get().setParameter(DagXLogInfoService.TOKEN, conf.get(OozieClient.LOG_TOKEN));
String user = conf.get(OozieClient.USER_NAME);
URI uri = new URI(conf.get(OozieClient.APP_PATH));
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
Configuration fsConf = has.createConfiguration(uri.getAuthority());
FileSystem fs = has.createFileSystem(user, uri, fsConf);
Path configDefault = null;
Configuration defaultConf = null;
// app path could be a directory
Path path = new Path(uri.getPath());
if (!fs.isFile(path)) {
configDefault = new Path(path, CONFIG_DEFAULT);
} else {
configDefault = new Path(path.getParent(), CONFIG_DEFAULT);
}
if (fs.exists(configDefault)) {
try {
defaultConf = new XConfiguration(fs.open(configDefault));
PropertiesUtils.checkDisallowedProperties(defaultConf, DISALLOWED_DEFAULT_PROPERTIES);
XConfiguration.injectDefaults(defaultConf, conf);
} catch (IOException ex) {
throw new IOException("default configuration file, " + ex.getMessage(), ex);
}
}
if (defaultConf != null) {
defaultConf = resolveDefaultConfVariables(defaultConf);
}
WorkflowApp app = wps.parseDef(conf, defaultConf);
XConfiguration protoActionConf = wps.createProtoActionConf(conf, true);
WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);
// Resolving all variables in the job properties.
// This ensures the Hadoop Configuration semantics is preserved.
XConfiguration resolvedVarsConf = new XConfiguration();
for (Map.Entry<String, String> entry : conf) {
resolvedVarsConf.set(entry.getKey(), conf.get(entry.getKey()));
}
conf = resolvedVarsConf;
WorkflowInstance wfInstance;
try {
wfInstance = workflowLib.createInstance(app, conf);
} catch (WorkflowException e) {
throw new StoreException(e);
}
Configuration conf = wfInstance.getConf();
// System.out.println("WF INSTANCE CONF:");
// System.out.println(XmlUtils.prettyPrint(conf).toString());
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setId(wfInstance.getId());
workflow.setAppName(ELUtils.resolveAppName(app.getName(), conf));
workflow.setAppPath(conf.get(OozieClient.APP_PATH));
workflow.setConf(XmlUtils.prettyPrint(conf).toString());
workflow.setProtoActionConf(protoActionConf.toXmlString());
workflow.setCreatedTime(new Date());
workflow.setLastModifiedTime(new Date());
workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
workflow.setStatus(WorkflowJob.Status.PREP);
workflow.setRun(0);
workflow.setUser(conf.get(OozieClient.USER_NAME));
workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
workflow.setWorkflowInstance(wfInstance);
workflow.setExternalId(conf.get(OozieClient.EXTERNAL_ID));
// Set parent id if it doesn't already have one (for subworkflows)
if (workflow.getParentId() == null) {
workflow.setParentId(conf.get(SubWorkflowActionExecutor.PARENT_ID));
}
// Set to coord action Id if workflow submitted through coordinator
if (workflow.getParentId() == null) {
workflow.setParentId(parentId);
}
LogUtils.setLogInfo(workflow);
LOG.debug("Workflow record created, Status [{0}]", workflow.getStatus());
Element wfElem = XmlUtils.parseXml(app.getDefinition());
ELEvaluator evalSla = createELEvaluatorForGroup(conf, "wf-sla-submit");
String jobSlaXml = verifySlaElements(wfElem, evalSla);
if (!dryrun) {
writeSLARegistration(wfElem, jobSlaXml, workflow.getId(), workflow.getParentId(), workflow.getUser(), workflow.getGroup(), workflow.getAppName(), LOG, evalSla);
workflow.setSlaXml(jobSlaXml);
// System.out.println("SlaXml :"+ slaXml);
// store.insertWorkflow(workflow);
insertList.add(workflow);
JPAService jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
try {
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
} catch (JPAExecutorException je) {
throw new CommandException(je);
}
} else {
LOG.error(ErrorCode.E0610);
return null;
}
return workflow.getId();
} else {
// Checking variable substitution for dryrun
ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(workflow, null, false, false);
Element workflowXml = XmlUtils.parseXml(app.getDefinition());
removeSlaElements(workflowXml);
String workflowXmlString = XmlUtils.removeComments(XmlUtils.prettyPrint(workflowXml).toString());
workflowXmlString = context.getELEvaluator().evaluate(workflowXmlString, String.class);
workflowXml = XmlUtils.parseXml(workflowXmlString);
Iterator<Element> it = workflowXml.getDescendants(new ElementFilter("job-xml"));
// Checking all variable substitutions in job-xml files
while (it.hasNext()) {
Element e = it.next();
String jobXml = e.getTextTrim();
Path xmlPath = new Path(workflow.getAppPath(), jobXml);
Configuration jobXmlConf = new XConfiguration(fs.open(xmlPath));
String jobXmlConfString = XmlUtils.prettyPrint(jobXmlConf).toString();
jobXmlConfString = XmlUtils.removeComments(jobXmlConfString);
context.getELEvaluator().evaluate(jobXmlConfString, String.class);
}
return "OK";
}
} catch (WorkflowException ex) {
throw new CommandException(ex);
} catch (HadoopAccessorException ex) {
throw new CommandException(ex);
} catch (Exception ex) {
throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
}
}
use of org.apache.oozie.store.StoreException in project oozie by apache.
the class SubmitHttpXCommand method execute.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#execute()
*/
@Override
protected String execute() throws CommandException {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
try {
XLog.Info.get().setParameter(DagXLogInfoService.TOKEN, conf.get(OozieClient.LOG_TOKEN));
String wfXml = getWorkflowXml(conf);
LOG.debug("workflow xml created on the server side is :\n");
LOG.debug(wfXml);
WorkflowApp app = wps.parseDef(wfXml, conf);
XConfiguration protoActionConf = wps.createProtoActionConf(conf, false);
WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);
// Resolving all variables in the job properties.
// This ensures the Hadoop Configuration semantics is preserved.
XConfiguration resolvedVarsConf = new XConfiguration();
for (Map.Entry<String, String> entry : conf) {
resolvedVarsConf.set(entry.getKey(), conf.get(entry.getKey()));
}
conf = resolvedVarsConf;
WorkflowInstance wfInstance;
try {
wfInstance = workflowLib.createInstance(app, conf);
} catch (WorkflowException e) {
throw new StoreException(e);
}
Configuration conf = wfInstance.getConf();
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setId(wfInstance.getId());
workflow.setAppName(app.getName());
workflow.setAppPath(conf.get(OozieClient.APP_PATH));
workflow.setConf(XmlUtils.prettyPrint(conf).toString());
workflow.setProtoActionConf(protoActionConf.toXmlString());
workflow.setCreatedTime(new Date());
workflow.setLastModifiedTime(new Date());
workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
workflow.setStatus(WorkflowJob.Status.PREP);
workflow.setRun(0);
workflow.setUser(conf.get(OozieClient.USER_NAME));
workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
workflow.setWorkflowInstance(wfInstance);
workflow.setExternalId(conf.get(OozieClient.EXTERNAL_ID));
LogUtils.setLogInfo(workflow);
JPAService jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
jpaService.execute(new WorkflowJobInsertJPAExecutor(workflow));
} else {
LOG.error(ErrorCode.E0610);
return null;
}
return workflow.getId();
} catch (WorkflowException ex) {
throw new CommandException(ex);
} catch (Exception ex) {
throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
}
}
use of org.apache.oozie.store.StoreException in project oozie by apache.
the class TestCoordRerunXCommand method addRecordToActionTable.
private void addRecordToActionTable(String jobId, int actionNum, String actionId, CoordinatorAction.Status status, String resourceXmlName, boolean isHCatDep) throws StoreException, IOException {
Path appPath = new Path(getFsTestCaseDir(), "coord");
String actionXml = null;
if (isHCatDep != true) {
actionXml = getCoordActionXml(appPath, resourceXmlName);
} else {
actionXml = getCoordActionXmlForHCat(appPath, resourceXmlName);
}
String actionNomialTime = getActionNomialTime(actionXml);
CoordinatorActionBean action = new CoordinatorActionBean();
action.setJobId(jobId);
action.setId(actionId);
action.setActionNumber(actionNum);
try {
action.setNominalTime(DateUtils.parseDateOozieTZ(actionNomialTime));
} catch (Exception e) {
e.printStackTrace();
fail("Unable to get action nominal time");
throw new IOException(e);
}
action.setLastModifiedTime(new Date());
action.setStatus(status);
action.setActionXml(actionXml);
Properties conf = getCoordProp(appPath);
String createdConf = XmlUtils.writePropToString(conf);
action.setCreatedConf(createdConf);
if (status.equals(CoordinatorAction.Status.FAILED)) {
action.setErrorCode("E1000");
action.setErrorMessage("Error");
}
try {
addRecordToCoordActionTable(action, null);
} catch (Exception e) {
e.printStackTrace();
fail("Unable to insert the test job record to table");
throw new StoreException(ErrorCode.E1019, e.getMessage());
}
}
use of org.apache.oozie.store.StoreException in project oozie by apache.
the class TestCoordRerunXCommand method addRecordToJobTable.
private void addRecordToJobTable(String jobId, CoordinatorJob.Status status) throws StoreException, IOException {
Path appPath = new Path(getFsTestCaseDir(), "coord");
String appXml = getCoordJobXml(appPath);
FileSystem fs = getFileSystem();
Writer writer = new OutputStreamWriter(fs.create(new Path(appPath + "/coordinator.xml")));
byte[] bytes = appXml.getBytes("UTF-8");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Reader reader2 = new InputStreamReader(bais);
IOUtils.copyCharStream(reader2, writer);
CoordinatorJobBean coordJob = new CoordinatorJobBean();
coordJob.setId(jobId);
coordJob.setAppName("COORD-TEST");
coordJob.setAppPath(appPath.toString());
coordJob.setStatus(status);
coordJob.setCreatedTime(new Date());
coordJob.setLastModifiedTime(new Date());
coordJob.setUser(getTestUser());
coordJob.setGroup(getTestGroup());
Properties conf = getCoordProp(appPath);
String confStr = XmlUtils.writePropToString(conf);
coordJob.setConf(confStr);
coordJob.setJobXml(appXml);
coordJob.setLastActionNumber(0);
coordJob.setFrequency("1");
coordJob.setExecutionOrder(Execution.FIFO);
coordJob.setConcurrency(1);
try {
coordJob.setStartTime(DateUtils.parseDateOozieTZ("2009-12-15T01:00Z"));
coordJob.setEndTime(DateUtils.parseDateOozieTZ("2009-12-17T01:00Z"));
} catch (Exception e) {
e.printStackTrace();
fail("Could not set Date/time");
}
try {
addRecordToCoordJobTable(coordJob);
} catch (Exception e) {
e.printStackTrace();
fail("Unable to insert the test job record to table");
throw new StoreException(ErrorCode.E1019, e.getMessage());
}
}
Aggregations