Search in sources :

Example 31 with WorkflowException

use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.

the class LiteWorkflowAppParser method getGlobalString.

/**
 * Write the GlobalSectionData to a Base64 string.
 * @param globalSectionData
 * @return String
 * @throws WorkflowException
 */
private String getGlobalString(GlobalSectionData globalSectionData) throws WorkflowException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream oos = null;
    try {
        Deflater def = new Deflater();
        oos = new DataOutputStream(new DeflaterOutputStream(baos, def));
        globalSectionData.write(oos);
        oos.close();
    } catch (IOException e) {
        throw new WorkflowException(ErrorCode.E0700, "Error while processing global section conf");
    }
    return Base64.encodeBase64String(baos.toByteArray());
}
Also used : Deflater(java.util.zip.Deflater) DataOutputStream(java.io.DataOutputStream) WorkflowException(org.apache.oozie.workflow.WorkflowException) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 32 with WorkflowException

use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.

the class DBLiteWorkflowLib method get.

/**
 * Loads the Workflow instance with the given ID.
 *
 * @param id
 * @return pInstance returns a workflow instance with the given ID
 * @throws WorkflowException
 */
@Override
public WorkflowInstance get(String id) throws WorkflowException {
    ParamChecker.notNull(id, "id");
    try {
        ResultSetReader rs = SqlStatement.parse(SqlStatement.selectColumns(OozieColumn.PI_state).where(SqlStatement.isEqual(OozieColumn.PI_wfId, ParamChecker.notNull(id, "id"))).prepareAndSetValues(connection).executeQuery());
        rs.next();
        LiteWorkflowInstance pInstance = WritableUtils.fromByteArray(rs.getByteArray(OozieColumn.PI_state), LiteWorkflowInstance.class);
        return pInstance;
    } catch (SQLException e) {
        throw new WorkflowException(ErrorCode.E0713, e.getMessage(), e);
    }
}
Also used : ResultSetReader(org.apache.oozie.util.db.SqlStatement.ResultSetReader) SQLException(java.sql.SQLException) WorkflowException(org.apache.oozie.workflow.WorkflowException)

Example 33 with WorkflowException

use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.

the class TestLiteWorkflowAppService method testActionNameLength.

public void testActionNameLength() throws Exception {
    setSystemProperty("oozie.service.ActionService.executor.ext.classes", TestActionExecutor.class.getName());
    Services services = new Services();
    try {
        services.init();
        Reader reader = IOUtils.getResourceAsReader("wf-schema-action-name-too-long.xml", -1);
        Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        WorkflowAppService wps = services.get(WorkflowAppService.class);
        Configuration jobConf = new XConfiguration();
        jobConf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
        jobConf.set(OozieClient.USER_NAME, getTestUser());
        try {
            LiteWorkflowApp app = (LiteWorkflowApp) wps.parseDef(jobConf);
            fail();
        } catch (WorkflowException ex) {
            assertEquals(ErrorCode.E0724, ex.getErrorCode());
        // nop
        }
    } finally {
        services.destroy();
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) FileWriter(java.io.FileWriter) WorkflowException(org.apache.oozie.workflow.WorkflowException) Reader(java.io.Reader) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 34 with WorkflowException

use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.

the class TestLiteWorkflowAppService method testMaxWfDefinition.

/**
 * Making sure an exception is thrown when a WF exceeds the maximum length
 *
 * @throws Exception
 */
public void testMaxWfDefinition() throws Exception {
    setSystemProperty(WorkflowAppService.CONFG_MAX_WF_LENGTH, "100");
    Services services = new Services();
    try {
        services.init();
        Reader reader = IOUtils.getResourceAsReader("wf-schema-valid.xml", -1);
        Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        Configuration conf = new XConfiguration();
        WorkflowAppService wps = services.get(WorkflowAppService.class);
        wps.readDefinition(getTestCaseFileUri("workflow.xml"), getTestUser(), conf);
        fail("an exception should be thrown as the definition exceeds the given maximum");
    } catch (WorkflowException wfe) {
        assertEquals(wfe.getErrorCode(), ErrorCode.E0736);
    } finally {
        services.destroy();
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) WorkflowException(org.apache.oozie.workflow.WorkflowException) Reader(java.io.Reader) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 35 with WorkflowException

use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.

the class TestLiteWorkflowAppService method testSchema.

public void testSchema() throws Exception {
    Services services = new Services();
    try {
        services.init();
        Reader reader = IOUtils.getResourceAsReader("wf-schema-valid.xml", -1);
        Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        WorkflowAppService wps = services.get(WorkflowAppService.class);
        Configuration jobConf = new XConfiguration();
        jobConf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
        jobConf.set(OozieClient.USER_NAME, getTestUser());
        WorkflowApp app = wps.parseDef(jobConf);
        assertNotNull(app);
        assertEquals("test-wf", app.getName());
        reader = IOUtils.getResourceAsReader("wf-schema-invalid.xml", -1);
        writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        try {
            wps.parseDef(jobConf);
            fail();
        } catch (WorkflowException ex) {
        // nop
        }
    } finally {
        services.destroy();
    }
}
Also used : LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) WorkflowException(org.apache.oozie.workflow.WorkflowException) Reader(java.io.Reader) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

WorkflowException (org.apache.oozie.workflow.WorkflowException)41 XConfiguration (org.apache.oozie.util.XConfiguration)23 IOException (java.io.IOException)15 Configuration (org.apache.hadoop.conf.Configuration)15 CommandException (org.apache.oozie.command.CommandException)8 Date (java.util.Date)7 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)7 Element (org.jdom.Element)7 ArrayList (java.util.ArrayList)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 JDOMException (org.jdom.JDOMException)6 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)5 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 File (java.io.File)4 Reader (java.io.Reader)4 URI (java.net.URI)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 Path (org.apache.hadoop.fs.Path)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 WorkflowApp (org.apache.oozie.workflow.WorkflowApp)4