use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class BundleStatusTransitXCommand method loadState.
@Override
protected void loadState() throws CommandException {
try {
bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_ID_STATUS_PENDING_MOD_PAUSE_SUSPEND_TIME, jobId);
bundleActions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_UNIGNORED_ACTION_STATUS_PENDING_FOR_BUNDLE, jobId);
for (BundleActionBean bAction : bundleActions) {
int counter = 0;
if (bundleActionStatus.containsKey(bAction.getStatus())) {
counter = getActionStatusCount(bAction.getStatus()) + 1;
} else {
++counter;
}
bundleActionStatus.put(bAction.getStatus(), counter);
if (bAction.getCoordId() == null && (bAction.getStatus() == Job.Status.FAILED || bAction.getStatus() == Job.Status.KILLED)) {
new BundleKillXCommand(jobId).call();
bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_ID_STATUS_PENDING_MOD_PAUSE_SUSPEND_TIME, jobId);
bundleJob.setStatus(Job.Status.FAILED);
bundleJob.setLastModifiedTime(new Date());
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS, bundleJob);
}
if (bAction.isPending()) {
LOG.debug(bAction + " has pending flag set");
foundPending = true;
}
}
LogUtils.setLogInfo(bundleJob);
} catch (JPAExecutorException e) {
throw new CommandException(ErrorCode.E1322, e);
}
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class BundleStartXCommand method insertBundleActions.
/**
* Insert bundle actions
*
* @throws CommandException thrown if failed to create bundle actions
*/
@SuppressWarnings("unchecked")
private void insertBundleActions() throws CommandException {
if (bundleJob != null) {
Map<String, Boolean> map = new HashMap<String, Boolean>();
try {
Element bAppXml = XmlUtils.parseXml(bundleJob.getJobXml());
List<Element> coordElems = bAppXml.getChildren("coordinator", bAppXml.getNamespace());
for (Element elem : coordElems) {
Attribute name = elem.getAttribute("name");
Attribute critical = elem.getAttribute("critical");
if (name != null) {
if (map.containsKey(name.getValue())) {
throw new CommandException(ErrorCode.E1304, name);
}
Configuration coordConf = mergeConfig(elem);
// skip coord job if it is not enabled
if (!isEnabled(elem, coordConf)) {
continue;
}
boolean isCritical = false;
if (critical != null && Boolean.parseBoolean(critical.getValue())) {
isCritical = true;
}
map.put(name.getValue(), isCritical);
} else {
throw new CommandException(ErrorCode.E1305);
}
}
} catch (JDOMException jex) {
throw new CommandException(ErrorCode.E1301, jex.getMessage(), jex);
}
// if there is no coordinator for this bundle, failed it.
if (map.isEmpty()) {
bundleJob.setStatus(Job.Status.FAILED);
bundleJob.resetPending();
try {
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PENDING, bundleJob);
} catch (JPAExecutorException jex) {
throw new CommandException(jex);
}
LOG.debug("No coord jobs for the bundle=[{0}], failed it!!", jobId);
throw new CommandException(ErrorCode.E1318, jobId);
}
for (Entry<String, Boolean> coordName : map.entrySet()) {
BundleActionBean action = createBundleAction(jobId, coordName.getKey(), coordName.getValue());
insertList.add(action);
}
} else {
throw new CommandException(ErrorCode.E0604, jobId);
}
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class BundleStartXCommand method updateBundleAction.
private void updateBundleAction() throws JPAExecutorException {
for (JsonBean bAction : insertList) {
BundleActionBean action = (BundleActionBean) bAction;
action.incrementAndGetPending();
action.setLastModifiedTime(new Date());
}
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class BatchQueryExecutor method executeBatchInsertUpdateDelete.
@SuppressWarnings("rawtypes")
public void executeBatchInsertUpdateDelete(Collection<JsonBean> insertList, Collection<UpdateEntry> updateList, Collection<JsonBean> deleteList) throws JPAExecutorException {
List<QueryEntry> queryList = new ArrayList<QueryEntry>();
JPAService jpaService = Services.get().get(JPAService.class);
EntityManager em = jpaService.getEntityManager();
if (updateList != null) {
for (UpdateEntry entry : updateList) {
Query query = null;
JsonBean bean = entry.getBean();
if (bean instanceof WorkflowJobBean) {
query = WorkflowJobQueryExecutor.getInstance().getUpdateQuery((WorkflowJobQuery) entry.getQueryName(), (WorkflowJobBean) entry.getBean(), em);
} else if (bean instanceof WorkflowActionBean) {
query = WorkflowActionQueryExecutor.getInstance().getUpdateQuery((WorkflowActionQuery) entry.getQueryName(), (WorkflowActionBean) entry.getBean(), em);
} else if (bean instanceof CoordinatorJobBean) {
query = CoordJobQueryExecutor.getInstance().getUpdateQuery((CoordJobQuery) entry.getQueryName(), (CoordinatorJobBean) entry.getBean(), em);
} else if (bean instanceof CoordinatorActionBean) {
query = CoordActionQueryExecutor.getInstance().getUpdateQuery((CoordActionQuery) entry.getQueryName(), (CoordinatorActionBean) entry.getBean(), em);
} else if (bean instanceof BundleJobBean) {
query = BundleJobQueryExecutor.getInstance().getUpdateQuery((BundleJobQuery) entry.getQueryName(), (BundleJobBean) entry.getBean(), em);
} else if (bean instanceof BundleActionBean) {
query = BundleActionQueryExecutor.getInstance().getUpdateQuery((BundleActionQuery) entry.getQueryName(), (BundleActionBean) entry.getBean(), em);
} else if (bean instanceof SLARegistrationBean) {
query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery((SLARegQuery) entry.getQueryName(), (SLARegistrationBean) entry.getBean(), em);
} else if (bean instanceof SLASummaryBean) {
query = SLASummaryQueryExecutor.getInstance().getUpdateQuery((SLASummaryQuery) entry.getQueryName(), (SLASummaryBean) entry.getBean(), em);
} else {
throw new JPAExecutorException(ErrorCode.E0603, "BatchQueryExecutor failed to construct a query");
}
queryList.add(new QueryEntry(entry.getQueryName(), query));
}
}
jpaService.executeBatchInsertUpdateDelete(insertList, queryList, deleteList, em);
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class BundleActionGetJPAExecutor method execute.
/* (non-Javadoc)
* @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
*/
@Override
@SuppressWarnings("unchecked")
public BundleActionBean execute(EntityManager em) throws JPAExecutorException {
List<BundleActionBean> baBeans;
try {
Query q = em.createNamedQuery("GET_BUNDLE_ACTION");
q.setParameter("bundleActionId", bundleActionId);
baBeans = q.getResultList();
} catch (Exception e) {
throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
}
BundleActionBean bean = null;
if (baBeans != null && baBeans.size() > 0) {
bean = baBeans.get(0);
return bean;
} else {
throw new JPAExecutorException(ErrorCode.E0605, bundleActionId);
}
}
Aggregations