Search in sources :

Example 1 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class BaseAdminServlet method doGet.

/**
 * Return safemode state, instrumentation, configuration, osEnv or
 * javaSysProps
 */
@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String resource = getResourceName(request);
    Instrumentation instr = Services.get().get(InstrumentationService.class).get();
    if (resource.equals(RestConstants.ADMIN_STATUS_RESOURCE)) {
        JSONObject json = new JSONObject();
        populateOozieMode(json);
        // json.put(JsonTags.SYSTEM_SAFE_MODE, getOozeMode());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_OS_ENV_RESOURCE)) {
        authorizeForSystemInfo(request);
        JSONObject json = new JSONObject();
        json.putAll(instr.getOSEnv());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_JAVA_SYS_PROPS_RESOURCE)) {
        authorizeForSystemInfo(request);
        JSONObject json = new JSONObject();
        json.putAll(instr.getJavaSystemProperties());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_CONFIG_RESOURCE)) {
        authorizeForSystemInfo(request);
        JSONObject json = new JSONObject();
        json.putAll(instr.getConfiguration());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_INSTRUMENTATION_RESOURCE)) {
        sendInstrumentationResponse(response, instr);
    } else if (resource.equals(RestConstants.ADMIN_BUILD_VERSION_RESOURCE)) {
        JSONObject json = new JSONObject();
        json.put(JsonTags.BUILD_VERSION, BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION));
        json.put(JsonTags.BUILD_INFO, BuildInfo.getBuildInfo());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_QUEUE_DUMP_RESOURCE)) {
        JSONObject json = new JSONObject();
        getQueueDump(json);
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_TIME_ZONES_RESOURCE)) {
        JSONObject json = new JSONObject();
        json.put(JsonTags.AVAILABLE_TIME_ZONES, availableTimeZonesToJsonArray());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_JMS_INFO)) {
        String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
        JsonBean jmsBean = getJMSConnectionInfo(request, response);
        sendJsonResponse(response, HttpServletResponse.SC_OK, jmsBean, timeZoneId);
    } else if (resource.equals(RestConstants.ADMIN_AVAILABLE_OOZIE_SERVERS_RESOURCE)) {
        JSONObject json = new JSONObject();
        json.putAll(getOozieURLs());
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else if (resource.equals(RestConstants.ADMIN_UPDATE_SHARELIB)) {
        authorizeRequest(request);
        updateShareLib(request, response);
    } else if (resource.equals(RestConstants.ADMIN_LIST_SHARELIB)) {
        String sharelibKey = request.getParameter(RestConstants.SHARE_LIB_REQUEST_KEY);
        sendJsonResponse(response, HttpServletResponse.SC_OK, getShareLib(sharelibKey));
    } else if (resource.equals(RestConstants.ADMIN_METRICS_RESOURCE)) {
        sendMetricsResponse(response);
    }
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) JSONObject(org.json.simple.JSONObject) Instrumentation(org.apache.oozie.util.Instrumentation) InstrumentationService(org.apache.oozie.service.InstrumentationService)

Example 2 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class TestHAPartitionDependencyManagerService method testPurgeMissingDependenciesForCache.

protected void testPurgeMissingDependenciesForCache(PartitionDependencyManagerService pdms) throws Exception {
    String actionId1 = "1234465451";
    String actionId2 = "1234465452";
    String actionId3 = "1234465453";
    // add partitions as missing
    HCatURI dep1 = new HCatURI("hcat://hcat-server1.domain.com:5080/mydb/mytbl1/dt=20120101;country=us");
    HCatURI dep2 = new HCatURI("hcat://hcat-server1.domain.com:5080/mydb/mytbl1/country=us;dt=20120101");
    HCatURI dep3 = new HCatURI("hcat://hcat-server2.domain.com:5080/mydb/mytbl2/dt=20120102;country=us");
    // actionId1-->(dep1,2), actionId2-->(dep2), actionId3-->(dep2,3)
    addMissingDependencyAndRegister(dep1, actionId1, pdms);
    addMissingDependencyAndRegister(dep2, actionId1, pdms);
    addMissingDependencyAndRegister(dep2, actionId2, pdms);
    addMissingDependencyAndRegister(dep2, actionId3, pdms);
    addMissingDependencyAndRegister(dep3, actionId3, pdms);
    List<String> waitingDep1 = (ArrayList<String>) pdms.getWaitingActions(dep1);
    assertEquals(waitingDep1.size(), 1);
    assertEquals(waitingDep1.get(0), actionId1);
    List<String> waitingDep2 = (ArrayList<String>) pdms.getWaitingActions(dep2);
    assertEquals(waitingDep2.size(), 3);
    for (String id : waitingDep2) {
        assertTrue(id.equals(actionId1) || id.equals(actionId2) || id.equals(actionId3));
    }
    List<String> waitingDep3 = (ArrayList<String>) pdms.getWaitingActions(dep3);
    assertEquals(waitingDep3.size(), 1);
    assertTrue(waitingDep3.get(0).equals(actionId3));
    // make only coordAction 1 to WAITING, the rest to RUNNING (only WAITING
    // remain dependency cache)
    ArrayList<JsonBean> insertList = new ArrayList<JsonBean>();
    CoordinatorActionBean coordAction1 = new CoordinatorActionBean();
    coordAction1.setId(actionId1);
    coordAction1.setStatus(Status.WAITING);
    insertList.add(coordAction1);
    CoordinatorActionBean coordAction2 = new CoordinatorActionBean();
    coordAction2.setId(actionId2);
    coordAction2.setStatus(Status.RUNNING);
    insertList.add(coordAction2);
    CoordinatorActionBean coordAction3 = new CoordinatorActionBean();
    coordAction3.setId(actionId3);
    coordAction3.setStatus(Status.RUNNING);
    insertList.add(coordAction3);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    // run cache purge
    Services.get().getConf().setInt(PartitionDependencyManagerService.CACHE_PURGE_TTL, 0);
    pdms.runCachePurgeWorker();
    // only coord Action 1 still in dependency cache
    waitingDep1 = (ArrayList<String>) pdms.getWaitingActions(dep1);
    assertEquals(waitingDep1.size(), 1);
    assertTrue(waitingDep1.get(0).equals(actionId1));
    // only coord Action 1 still in dependency cache
    waitingDep2 = (ArrayList<String>) pdms.getWaitingActions(dep2);
    assertEquals(waitingDep2.size(), 1);
    assertTrue(waitingDep2.get(0).equals(actionId1));
    waitingDep3 = (ArrayList<String>) pdms.getWaitingActions(dep3);
    assertNull(waitingDep3);
    HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
    // mytbl1 should be still in topic map
    assertTrue(hcatService.isRegisteredForNotification(dep1));
    // mytbl1 should be still in topic map
    assertTrue(hcatService.isRegisteredForNotification(dep2));
    // mytbl2 should NOT be in topic map
    assertFalse(hcatService.isRegisteredForNotification(dep3));
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) HCatURI(org.apache.oozie.util.HCatURI)

Example 3 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class DummySLACalculatorMemory method createWorkflow.

private WorkflowJobBean createWorkflow(String id) throws Exception {
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    WorkflowJobBean workflow = new WorkflowJobBean();
    workflow.setId(id);
    workflow.setStatusStr("PREP");
    workflow.setStartTime(new Date());
    workflow.setSlaXml("<sla></sla>");
    insertList.add(workflow);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
    return workflow;
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Example 4 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class SLACalculatorMemory method addRegistration.

/**
 * Register a new job into the map for SLA tracking
 * @return true if successful
 */
@Override
public boolean addRegistration(String jobId, SLARegistrationBean reg) throws JPAExecutorException {
    try {
        if (slaMap.size() < capacity) {
            SLACalcStatus slaCalc = new SLACalcStatus(reg);
            slaCalc.setSLAStatus(SLAStatus.NOT_STARTED);
            slaCalc.setJobStatus(getJobStatus(reg.getAppType()));
            List<JsonBean> insertList = new ArrayList<JsonBean>();
            final SLASummaryBean summaryBean = new SLASummaryBean(slaCalc);
            final Timestamp currentTime = DateUtils.convertDateToTimestamp(new Date());
            reg.setCreatedTimestamp(currentTime);
            summaryBean.setCreatedTimestamp(currentTime);
            insertList.add(reg);
            insertList.add(summaryBean);
            BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
            putAndIncrement(jobId, slaCalc);
            LOG.trace("SLA Registration Event - Job:" + jobId);
            return true;
        } else {
            setLogPrefix(reg.getId());
            LOG.error("SLACalculator memory capacity reached. Cannot add or update new SLA Registration entry for job [{0}]", reg.getId());
            LogUtils.clearLogPrefix();
        }
    } catch (JPAExecutorException jpa) {
        throw jpa;
    }
    return false;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JsonBean(org.apache.oozie.client.rest.JsonBean) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 5 with JsonBean

use of org.apache.oozie.client.rest.JsonBean in project oozie by apache.

the class TestSLACalculationJPAExecutor method testRollback.

/**
 * Test inserts and updates rollback
 *
 * @throws Exception
 */
@Test
public void testRollback() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    String wfId1 = "workflow-1";
    String wfId2 = "workflow-2";
    // initial insert
    SLASummaryBean bean1 = _createSLASummaryBean(wfId1, "RUNNING", EventStatus.START_MISS, new Date(), new Date(), 1000, null, null, 2000, 0, null);
    List<JsonBean> list = new ArrayList<JsonBean>();
    list.add(bean1);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(list, null, null);
    // update existing record and insert another
    Date newDate = new Date();
    bean1 = new SLASummaryBean();
    bean1.setId(wfId1);
    bean1.setActualEnd(newDate);
    List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
    updateList.add(new UpdateEntry<SLASummaryQuery>(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, bean1));
    SLASummaryBean bean2 = _createSLASummaryBean(wfId2, "RUNNING", EventStatus.END_MISS, new Date(), new Date(), 1000, null, null, 2000, 0, null);
    List<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(bean2);
    // set fault injection to true, so transaction is roll backed
    setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
    try {
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        fail("Expected exception due to commit failure but didn't get any");
    } catch (Exception e) {
    }
    FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
    // Check whether transactions are rolled back or not
    SLASummaryBean sBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, wfId1);
    // isSlaProcessed should NOT be changed to 1
    // actualEnd should be null as before
    assertNull(sBean.getActualEnd());
    sBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, wfId2);
    // new bean should not have been inserted due to rollback
    assertNull(sBean);
}
Also used : JsonBean(org.apache.oozie.client.rest.JsonBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) SLASummaryQuery(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor.SLASummaryQuery) Test(org.junit.Test)

Aggregations

JsonBean (org.apache.oozie.client.rest.JsonBean)28 ArrayList (java.util.ArrayList)20 Date (java.util.Date)15 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)10 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)9 JPAService (org.apache.oozie.service.JPAService)9 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)7 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)7 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)6 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)5 BundleActionBean (org.apache.oozie.BundleActionBean)3 CommandException (org.apache.oozie.command.CommandException)3 IOException (java.io.IOException)2 BundleJobBean (org.apache.oozie.BundleJobBean)2 DagEngine (org.apache.oozie.DagEngine)2 DagEngineException (org.apache.oozie.DagEngineException)2 PreconditionException (org.apache.oozie.command.PreconditionException)2