Search in sources :

Example 16 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestJMSTopicService method testMixedTopic1.

@Test
public void testMixedTopic1() throws Exception {
    services = setupServicesForTopic();
    services.getConf().set(JMSTopicService.TOPIC_NAME, JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow," + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord, default = " + JMSTopicService.TopicType.JOBID.getValue());
    services.init();
    JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
    WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_JOB, wfj.getUser(), wfj.getId(), null));
    WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
    assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_ACTION, wfj.getUser(), wab.getId(), wab.getWfId()));
    CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
    assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
    assertEquals("coord", jmsTopicService.getTopic(AppType.COORDINATOR_JOB, cjb.getUser(), cjb.getId(), null));
    CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-for-action-input-check.xml", 0);
    assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
    assertEquals("coord", jmsTopicService.getTopic(AppType.COORDINATOR_ACTION, cjb.getUser(), cab.getId(), cab.getJobId()));
    BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
    assertEquals(bjb.getId(), jmsTopicService.getTopic(bjb.getId()));
    assertEquals(bjb.getId(), jmsTopicService.getTopic(AppType.BUNDLE_JOB, bjb.getUser(), bjb.getId(), null));
    BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
    assertEquals(bjb.getId(), jmsTopicService.getTopic(bab.getBundleActionId()));
    assertEquals(bjb.getId(), jmsTopicService.getTopic(AppType.BUNDLE_ACTION, bjb.getUser(), bab.getBundleActionId(), bab.getBundleId()));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobBean(org.apache.oozie.BundleJobBean) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) BundleActionBean(org.apache.oozie.BundleActionBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Test(org.junit.Test)

Example 17 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class TestJMSTopicService method testMixedTopic2.

@Test
public void testMixedTopic2() throws Exception {
    services = setupServicesForTopic();
    services.getConf().set(JMSTopicService.TOPIC_NAME, JMSTopicService.JobType.WORKFLOW.getValue() + " = workflow," + JMSTopicService.JobType.COORDINATOR.getValue() + "=coord");
    services.init();
    JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
    WorkflowJobBean wfj = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    assertEquals("workflow", jmsTopicService.getTopic(wfj.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_JOB, wfj.getUser(), wfj.getId(), null));
    WorkflowActionBean wab = addRecordToWfActionTable(wfj.getId(), "1", WorkflowAction.Status.RUNNING);
    assertEquals("workflow", jmsTopicService.getTopic(wab.getId()));
    assertEquals("workflow", jmsTopicService.getTopic(AppType.WORKFLOW_ACTION, wfj.getUser(), wab.getId(), wab.getWfId()));
    CoordinatorJobBean cjb = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, true, true);
    assertEquals("coord", jmsTopicService.getTopic(cjb.getId()));
    CoordinatorActionBean cab = addRecordToCoordActionTable(cjb.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-for-action-input-check.xml", 0);
    assertEquals("coord", jmsTopicService.getTopic(cab.getId()));
    assertEquals("coord", jmsTopicService.getTopic(AppType.COORDINATOR_ACTION, cjb.getUser(), cab.getId(), cab.getJobId()));
    BundleJobBean bjb = addRecordToBundleJobTable(Job.Status.RUNNING, true);
    // As no default is specified, user will be considered as topic
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(bjb.getId()));
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(AppType.BUNDLE_JOB, bjb.getUser(), bjb.getId(), null));
    BundleActionBean bab = addRecordToBundleActionTable(bjb.getId(), "1", 1, Job.Status.RUNNING);
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(bab.getBundleActionId()));
    assertEquals(bjb.getUser(), jmsTopicService.getTopic(AppType.BUNDLE_ACTION, bjb.getUser(), bab.getBundleActionId(), bab.getBundleId()));
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleJobBean(org.apache.oozie.BundleJobBean) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) BundleActionBean(org.apache.oozie.BundleActionBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Test(org.junit.Test)

Example 18 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class ForTestWorkflowStoreService method create.

public WorkflowStore create() throws StoreException {
    final WorkflowStore wfs = super.create();
    return new WorkflowStore() {

        public void insertWorkflow(WorkflowJobBean workflow) throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public WorkflowJobBean getWorkflow(String id, boolean locking) throws StoreException {
            WorkflowJobBean wf = new WorkflowJobBean();
            wf.setId(id);
            wf.setUser("u");
            wf.setGroup("g");
            return wf;
        }

        public WorkflowJobBean getWorkflowInfo(String id) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public String getWorkflowIdForExternalId(String extId) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public void updateWorkflow(WorkflowJobBean workflow) throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public int getWorkflowCountWithStatus(String status) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return 0;
        }

        public int getWorkflowCountWithStatusInLastNSeconds(String status, int secs) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return 0;
        }

        public void insertAction(WorkflowActionBean action) throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public WorkflowActionBean getAction(String id, boolean locking) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public void updateAction(WorkflowActionBean action) throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public void deleteAction(String id) throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public List<WorkflowActionBean> getActionsForWorkflow(String id, boolean locking) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public List<WorkflowActionBean> getPendingActions(long minimumPendingAgeSecs) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public List<WorkflowActionBean> getRunningActions(long checkAgeSecs) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public WorkflowsInfo getWorkflowsInfo(Map<String, List<String>> filter, int start, int len) throws StoreException {
            // To change body of implemented methods use File | Settings | File Templates.
            return null;
        }

        public void purge(long olderThanDays) throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public void commit() throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        public void close() throws StoreException {
        // To change body of implemented methods use File | Settings | File Templates.
        }
    };
}
Also used : WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Map(java.util.Map) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 19 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class JavaActionExecutor method getCredProperties.

@SuppressWarnings("unchecked")
protected CredentialsProperties getCredProperties(Context context, String credName) throws Exception {
    CredentialsProperties credProp = null;
    String workflowXml = ((WorkflowJobBean) context.getWorkflow()).getWorkflowInstance().getApp().getDefinition();
    XConfiguration wfjobConf = getWorkflowConf(context);
    Element elementJob = XmlUtils.parseXml(workflowXml);
    Element credentials = elementJob.getChild("credentials", elementJob.getNamespace());
    if (credentials != null) {
        for (Element credential : (List<Element>) credentials.getChildren("credential", credentials.getNamespace())) {
            String name = credential.getAttributeValue("name");
            String type = credential.getAttributeValue("type");
            LOG.debug("getCredProperties: Name: " + name + ", Type: " + type);
            if (name.equalsIgnoreCase(credName)) {
                credProp = new CredentialsProperties(name, type);
                for (Element property : (List<Element>) credential.getChildren("property", credential.getNamespace())) {
                    String propertyName = property.getChildText("name", property.getNamespace());
                    String propertyValue = property.getChildText("value", property.getNamespace());
                    ELEvaluator eval = new ELEvaluator();
                    for (Map.Entry<String, String> entry : wfjobConf) {
                        eval.setVariable(entry.getKey(), entry.getValue().trim());
                    }
                    propertyName = eval.evaluate(propertyName, String.class);
                    propertyValue = eval.evaluate(propertyValue, String.class);
                    credProp.getProperties().put(propertyName, propertyValue);
                    LOG.debug("getCredProperties: Properties name :'" + propertyName + "', Value : '" + propertyValue + "'");
                }
            }
        }
        if (credProp == null && credName != null) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "JA021", "Could not load credentials with name [{0}]].", credName);
        }
    } else {
        LOG.debug("credentials is null for the action");
    }
    return credProp;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ELEvaluator(org.apache.oozie.util.ELEvaluator) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with WorkflowJobBean

use of org.apache.oozie.WorkflowJobBean in project oozie by apache.

the class SubWorkflowActionExecutor method getWorkflowClient.

protected OozieClient getWorkflowClient(Context context, String oozieUri) {
    OozieClient oozieClient;
    if (oozieUri.equals(LOCAL)) {
        WorkflowJobBean workflow = (WorkflowJobBean) context.getWorkflow();
        String user = workflow.getUser();
        String group = workflow.getGroup();
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(user);
        oozieClient = new LocalOozieClient(dagEngine);
    } else {
        // TODO we need to add authToken to the WC for the remote case
        oozieClient = new OozieClient(oozieUri);
    }
    return oozieClient;
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) LocalOozieClient(org.apache.oozie.LocalOozieClient) DagEngine(org.apache.oozie.DagEngine) DagEngineService(org.apache.oozie.service.DagEngineService) LocalOozieClient(org.apache.oozie.LocalOozieClient) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Aggregations

WorkflowJobBean (org.apache.oozie.WorkflowJobBean)304 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)164 JPAService (org.apache.oozie.service.JPAService)95 XConfiguration (org.apache.oozie.util.XConfiguration)94 Configuration (org.apache.hadoop.conf.Configuration)66 Date (java.util.Date)60 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)58 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)57 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)53 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)53 Path (org.apache.hadoop.fs.Path)50 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)32 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)30 Element (org.jdom.Element)28 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)26 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)25 HashMap (java.util.HashMap)23 BundleJobBean (org.apache.oozie.BundleJobBean)21