Search in sources :

Example 1 with WorkflowDefinitionReport

use of org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport in project opencast by opencast.

the class WorkflowServiceSolrIndex method getStatistics.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.impl.WorkflowServiceIndex#getStatistics()
 */
@Override
public WorkflowStatistics getStatistics() throws WorkflowDatabaseException {
    long total = 0;
    long paused = 0;
    long failed = 0;
    long failing = 0;
    long instantiated = 0;
    long running = 0;
    long stopped = 0;
    long succeeded = 0;
    WorkflowStatistics stats = new WorkflowStatistics();
    // Get all definitions and then query for the numbers and the current operation per definition
    try {
        String orgId = securityService.getOrganization().getId();
        StringBuilder queryString = new StringBuilder().append(ORG_KEY).append(":").append(escapeQueryChars(orgId));
        appendSolrAuthFragment(queryString, Permissions.Action.WRITE.toString());
        SolrQuery solrQuery = new SolrQuery(queryString.toString());
        solrQuery.addFacetField(WORKFLOW_DEFINITION_KEY);
        solrQuery.addFacetField(OPERATION_KEY);
        solrQuery.setFacetMinCount(0);
        solrQuery.setFacet(true);
        QueryResponse response = solrServer.query(solrQuery);
        FacetField templateFacet = response.getFacetField(WORKFLOW_DEFINITION_KEY);
        FacetField operationFacet = response.getFacetField(OPERATION_KEY);
        // For every template and every operation
        if (templateFacet != null && templateFacet.getValues() != null) {
            for (Count template : templateFacet.getValues()) {
                WorkflowDefinitionReport templateReport = new WorkflowDefinitionReport();
                templateReport.setId(template.getName());
                long templateTotal = 0;
                long templatePaused = 0;
                long templateFailed = 0;
                long templateFailing = 0;
                long templateInstantiated = 0;
                long templateRunning = 0;
                long templateStopped = 0;
                long templateSucceeded = 0;
                if (operationFacet != null && operationFacet.getValues() != null) {
                    for (Count operation : operationFacet.getValues()) {
                        OperationReport operationReport = new OperationReport();
                        operationReport.setId(operation.getName());
                        StringBuilder baseSolrQuery = new StringBuilder().append(ORG_KEY).append(":").append(escapeQueryChars(orgId));
                        appendSolrAuthFragment(baseSolrQuery, Permissions.Action.WRITE.toString());
                        solrQuery = new SolrQuery(baseSolrQuery.toString());
                        solrQuery.addFacetField(STATE_KEY);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.FAILED);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.FAILING);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.INSTANTIATED);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.PAUSED);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.RUNNING);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.STOPPED);
                        solrQuery.addFacetQuery(STATE_KEY + ":" + WorkflowState.SUCCEEDED);
                        solrQuery.addFilterQuery(WORKFLOW_DEFINITION_KEY + ":" + template.getName());
                        solrQuery.addFilterQuery(OPERATION_KEY + ":" + operation.getName());
                        solrQuery.setFacetMinCount(0);
                        solrQuery.setFacet(true);
                        response = solrServer.query(solrQuery);
                        // Add the states
                        FacetField stateFacet = response.getFacetField(STATE_KEY);
                        for (Count stateValue : stateFacet.getValues()) {
                            WorkflowState state = WorkflowState.valueOf(stateValue.getName().toUpperCase());
                            templateTotal += stateValue.getCount();
                            total += stateValue.getCount();
                            switch(state) {
                                case FAILED:
                                    operationReport.setFailed(stateValue.getCount());
                                    templateFailed += stateValue.getCount();
                                    failed += stateValue.getCount();
                                    break;
                                case FAILING:
                                    operationReport.setFailing(stateValue.getCount());
                                    templateFailing += stateValue.getCount();
                                    failing += stateValue.getCount();
                                    break;
                                case INSTANTIATED:
                                    operationReport.setInstantiated(stateValue.getCount());
                                    templateInstantiated += stateValue.getCount();
                                    instantiated += stateValue.getCount();
                                    break;
                                case PAUSED:
                                    operationReport.setPaused(stateValue.getCount());
                                    templatePaused += stateValue.getCount();
                                    paused += stateValue.getCount();
                                    break;
                                case RUNNING:
                                    operationReport.setRunning(stateValue.getCount());
                                    templateRunning += stateValue.getCount();
                                    running += stateValue.getCount();
                                    break;
                                case STOPPED:
                                    operationReport.setStopped(stateValue.getCount());
                                    templateStopped += stateValue.getCount();
                                    stopped += stateValue.getCount();
                                    break;
                                case SUCCEEDED:
                                    operationReport.setFinished(stateValue.getCount());
                                    templateSucceeded += stateValue.getCount();
                                    succeeded += stateValue.getCount();
                                    break;
                                default:
                                    throw new IllegalStateException("State '" + state + "' is not handled");
                            }
                        }
                        templateReport.getOperations().add(operationReport);
                    }
                }
                // Update the template statistics
                templateReport.setTotal(templateTotal);
                templateReport.setFailed(templateFailed);
                templateReport.setFailing(templateFailing);
                templateReport.setInstantiated(templateInstantiated);
                templateReport.setPaused(templatePaused);
                templateReport.setRunning(templateRunning);
                templateReport.setStopped(templateStopped);
                templateReport.setFinished(templateSucceeded);
                // Add the definition report to the statistics
                stats.getDefinitions().add(templateReport);
            }
        }
    } catch (SolrServerException e) {
        throw new WorkflowDatabaseException(e);
    }
    stats.setTotal(total);
    stats.setFailed(failed);
    stats.setFailing(failing);
    stats.setInstantiated(instantiated);
    stats.setPaused(paused);
    stats.setRunning(running);
    stats.setStopped(stopped);
    stats.setFinished(succeeded);
    return stats;
}
Also used : WorkflowDefinitionReport(org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport) SolrServerException(org.apache.solr.client.solrj.SolrServerException) FacetField(org.apache.solr.client.solrj.response.FacetField) Count(org.apache.solr.client.solrj.response.FacetField.Count) WorkflowStatistics(org.opencastproject.workflow.api.WorkflowStatistics) SolrQuery(org.apache.solr.client.solrj.SolrQuery) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowState(org.opencastproject.workflow.api.WorkflowInstance.WorkflowState) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OperationReport(org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport.OperationReport)

Example 2 with WorkflowDefinitionReport

use of org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport in project opencast by opencast.

the class WorkflowStatisticsTest method testStatisticsMarshalling.

/**
 * @throws Exception
 */
@Test
public void testStatisticsMarshalling() throws Exception {
    WorkflowStatistics stats = new WorkflowStatistics();
    stats.setFailed(100);
    stats.setInstantiated(20);
    OperationReport op1 = new OperationReport();
    op1.setId("compose");
    op1.setInstantiated(10);
    op1.setFailing(1);
    List<OperationReport> ops1 = new ArrayList<WorkflowStatistics.WorkflowDefinitionReport.OperationReport>();
    ops1.add(op1);
    WorkflowDefinitionReport def1 = new WorkflowDefinitionReport();
    def1.setFailed(40);
    def1.setInstantiated(10);
    def1.setOperations(ops1);
    def1.setId("def1");
    def1.setOperations(ops1);
    WorkflowDefinitionReport def2 = new WorkflowDefinitionReport();
    def1.setFailed(60);
    def1.setInstantiated(10);
    List<WorkflowDefinitionReport> reports = new ArrayList<WorkflowDefinitionReport>();
    reports.add(def1);
    reports.add(def2);
    stats.setDefinitions(reports);
}
Also used : WorkflowDefinitionReport(org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport) OperationReport(org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport.OperationReport) ArrayList(java.util.ArrayList) WorkflowStatistics(org.opencastproject.workflow.api.WorkflowStatistics) Test(org.junit.Test)

Aggregations

WorkflowStatistics (org.opencastproject.workflow.api.WorkflowStatistics)2 WorkflowDefinitionReport (org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport)2 OperationReport (org.opencastproject.workflow.api.WorkflowStatistics.WorkflowDefinitionReport.OperationReport)2 ArrayList (java.util.ArrayList)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 FacetField (org.apache.solr.client.solrj.response.FacetField)1 Count (org.apache.solr.client.solrj.response.FacetField.Count)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 Test (org.junit.Test)1 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)1 WorkflowState (org.opencastproject.workflow.api.WorkflowInstance.WorkflowState)1