← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9994: Web api, made it possible to initiate updates of resource tables, analytics tables and data mart ...

 

------------------------------------------------------------
revno: 9994
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-03-05 23:03:40 +0100
message:
  Web api, made it possible to initiate updates of resource tables, analytics tables and data mart through the web api resource table resource
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java
  dhis-2/dhis-services/dhis-service-analytics/pom.xml
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2013-03-05 21:37:21 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2013-03-05 22:03:40 +0000
@@ -270,6 +270,8 @@
         
         sql += ")";
         
+        log.info( "Create period structure SQL: " + sql );
+        
         jdbcTemplate.update( sql );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/pom.xml'
--- dhis-2/dhis-services/dhis-service-analytics/pom.xml	2013-03-05 19:05:37 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/pom.xml	2013-03-05 22:03:40 +0000
@@ -27,6 +27,10 @@
     </dependency>
     <dependency>
       <groupId>org.hisp.dhis</groupId>
+      <artifactId>dhis-service-administration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.hisp.dhis</groupId>
       <artifactId>dhis-support-system</artifactId>
     </dependency>
     

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java	2013-03-04 14:44:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableService.java	2013-03-05 22:03:40 +0000
@@ -27,8 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.concurrent.Future;
-
 import org.hisp.dhis.scheduling.TaskId;
 
 public interface AnalyticsTableService
@@ -39,5 +37,5 @@
      * @param last3Years whether to update last 3 years of data only or all.
      * @param taskId the TaskId.
      */
-    Future<?> update( boolean last3Years, TaskId id );
+    void update( boolean last3Years, TaskId id );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java	2013-03-05 19:00:51 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/scheduling/AnalyticsTableTask.java	2013-03-05 22:03:40 +0000
@@ -30,14 +30,12 @@
 import static org.hisp.dhis.scheduling.TaskCategory.DATAMART;
 import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
 
-import java.util.concurrent.ExecutionException;
-
 import javax.annotation.Resource;
 
 import org.hisp.dhis.analytics.AnalyticsTableService;
+import org.hisp.dhis.resourcetable.ResourceTableService;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.system.notification.Notifier;
-import org.hisp.dhis.system.util.DebugUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
 /**
@@ -56,6 +54,9 @@
     private AnalyticsTableService completenessTargetTableService;
     
     @Autowired
+    private ResourceTableService resourceTableService;
+    
+    @Autowired
     private Notifier notifier;
 
     private boolean last3Years;
@@ -79,29 +80,22 @@
     @Override
     public void run()
     {
-        try
-        {
-            notifier.clear( taskId, DATAMART ).notify( taskId, DATAMART, "Updating analytics tables" );
-            
-            analyticsTableService.update( last3Years, taskId ).get();
-            
-            notifier.notify( taskId, DATAMART, "Updating completeness tables" );
-            
-            completenessTableService.update( last3Years, taskId ).get();
-
-            notifier.notify( taskId, DATAMART, "Updating compeleteness target table" );
-            
-            completenessTargetTableService.update( last3Years, taskId ).get();
-            
-            notifier.notify( taskId, DATAMART, INFO, "Analytics tables updated", true );
-        }
-        catch ( ExecutionException ex )
-        {
-            throw new RuntimeException( "Failed to execute task: " + DebugUtils.getStackTrace( ex ), ex );
-        }
-        catch ( InterruptedException ex )
-        {
-            throw new RuntimeException( "Task was interrupted: " + DebugUtils.getStackTrace( ex ), ex );
-        }        
+        notifier.clear( taskId, DATAMART ).notify( taskId, DATAMART, "Updating resource tables" );
+        
+        resourceTableService.generateAll();
+
+        notifier.notify( taskId, DATAMART, "Updating analytics tables" );
+        
+        analyticsTableService.update( last3Years, taskId );
+        
+        notifier.notify( taskId, DATAMART, "Updating completeness tables" );
+        
+        completenessTableService.update( last3Years, taskId );
+
+        notifier.notify( taskId, DATAMART, "Updating compeleteness target table" );
+        
+        completenessTargetTableService.update( last3Years, taskId );
+        
+        notifier.notify( taskId, DATAMART, INFO, "Analytics tables updated", true );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2013-03-05 19:22:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2013-03-05 22:03:40 +0000
@@ -51,10 +51,8 @@
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.Clock;
 import org.hisp.dhis.system.util.ConcurrentUtils;
-import org.hisp.dhis.system.util.DebugUtils;
 import org.hisp.dhis.system.util.SystemUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
 
 public class DefaultAnalyticsTableService
     implements AnalyticsTableService
@@ -81,66 +79,53 @@
     // Implementation
     // -------------------------------------------------------------------------
     
-    @Async
-    public Future<?> update( boolean last3YearsOnly, TaskId taskId )
+    public void update( boolean last3YearsOnly, TaskId taskId )
     {
         Clock clock = new Clock().startClock().logTime( "Starting update" );
         
-        try
-        {
-            final Date threeYrsAgo = new Cal().subtract( Calendar.YEAR, 2 ).set( 1, 1 ).time();
-            final Date earliest = last3YearsOnly ? threeYrsAgo : tableManager.getEarliestData();
-            final Date latest = tableManager.getLatestData();
-            final String tableName = tableManager.getTableName();
-            final List<String> tables = PartitionUtils.getTempTableNames( earliest, latest, tableName );        
-            clock.logTime( "Got partition tables: " + tables + ", earliest: " + earliest + ", latest: " + latest );
-            
-            notifier.notify( taskId, DATAMART, "Creating analytics tables" );
-            
-            createTables( tables );
-            
-            clock.logTime( "Created analytics tables" );
-            notifier.notify( taskId, DATAMART, "Populating analytics tables" );
-            
-            populateTables( tables );
-            
-            clock.logTime( "Populated analytics tables" );
-            notifier.notify( taskId, DATAMART, "Pruned analytics tables" );
-            
-            pruneTables( tables );
-            
-            clock.logTime( "Pruned analytics tables" );
-            notifier.notify( taskId, DATAMART, "Applying aggregation levels" );
-            
-            applyAggregationLevels( tables );
-            
-            clock.logTime( "Applied aggregation levels" );
-            notifier.notify( taskId, DATAMART, "Creating indexes" );
-            
-            createIndexes( tables );
-            
-            clock.logTime( "Created indexes" );
-            notifier.notify( taskId, DATAMART, "Vacuuming tables" );
-            
-            vacuumTables( tables );
-            
-            clock.logTime( "Vacuumed tables" );
-            notifier.notify( taskId, DATAMART, "Swapping analytics tables" );
-            
-            swapTables( tables );
-            
-            clock.logTime( "Swapped analytics tables" );
-            
-            clock.logTime( "Table update done" );
-            notifier.notify( taskId, DATAMART, "Table update done" );
-        }
-        catch ( Exception ex )
-        {
-            log.error( "Error during analytics table generation", ex );
-            log.error( DebugUtils.getStackTrace( ex ) );
-        }
-        
-        return null;
+        final Date threeYrsAgo = new Cal().subtract( Calendar.YEAR, 2 ).set( 1, 1 ).time();
+        final Date earliest = last3YearsOnly ? threeYrsAgo : tableManager.getEarliestData();
+        final Date latest = tableManager.getLatestData();
+        final String tableName = tableManager.getTableName();
+        final List<String> tables = PartitionUtils.getTempTableNames( earliest, latest, tableName );        
+        clock.logTime( "Got partition tables: " + tables + ", earliest: " + earliest + ", latest: " + latest );
+        
+        notifier.notify( taskId, DATAMART, "Creating analytics tables" );
+        
+        createTables( tables );
+        
+        clock.logTime( "Created analytics tables" );
+        notifier.notify( taskId, DATAMART, "Populating analytics tables" );
+        
+        populateTables( tables );
+        
+        clock.logTime( "Populated analytics tables" );
+        notifier.notify( taskId, DATAMART, "Pruned analytics tables" );
+        
+        pruneTables( tables );
+        
+        clock.logTime( "Pruned analytics tables" );
+        notifier.notify( taskId, DATAMART, "Applying aggregation levels" );
+        
+        applyAggregationLevels( tables );
+        
+        clock.logTime( "Applied aggregation levels" );
+        notifier.notify( taskId, DATAMART, "Creating indexes" );
+        
+        createIndexes( tables );
+        
+        clock.logTime( "Created indexes" );
+        notifier.notify( taskId, DATAMART, "Vacuuming tables" );
+        
+        vacuumTables( tables );
+        
+        clock.logTime( "Vacuumed tables" );
+        notifier.notify( taskId, DATAMART, "Swapping analytics tables" );
+        
+        swapTables( tables );
+        
+        clock.logTime( "Table update done" );
+        notifier.notify( taskId, DATAMART, "Table update done" );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java	2012-04-03 22:08:32 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java	2013-03-05 22:03:40 +0000
@@ -30,11 +30,11 @@
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 
-import org.hisp.dhis.analytics.AnalyticsTableService;
+import org.hisp.dhis.analytics.scheduling.AnalyticsTableTask;
 import org.hisp.dhis.api.utils.ContextUtils;
-import org.hisp.dhis.resourcetable.ResourceTableService;
+import org.hisp.dhis.resourcetable.scheduling.ResourceTableTask;
+import org.hisp.dhis.scheduling.DataMartTask;
 import org.hisp.dhis.system.scheduling.Scheduler;
-import org.hisp.dhis.user.CurrentUserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
@@ -50,57 +50,42 @@
 {
     public static final String RESOURCE_PATH = "/resourceTables";
     
-    @Resource(name="org.hisp.dhis.analytics.AnalyticsTableService")
-    private AnalyticsTableService analyticsTableService;
-
-    @Resource(name="org.hisp.dhis.analytics.CompletenessTableService")
-    private AnalyticsTableService completenessTableService;
-    
-    @Resource(name="org.hisp.dhis.analytics.CompletenessTargetTableService")
-    private AnalyticsTableService completenessTargetTableService;
-    
-    @Autowired
-    private ResourceTableService resourceTableService;
-    
-    @Autowired
-    private CurrentUserService currentUserService;
+    @Resource(name="analyticsAllTask")
+    private AnalyticsTableTask analyticsTableTask;
+    
+    @Resource(name="dataMartLast12MonthsTask")
+    private DataMartTask dataMartTask;
+    
+    @Autowired
+    private ResourceTableTask resourceTableTask;
     
     @Autowired
     private Scheduler scheduler;
     
     @RequestMapping( value = "/analytics", method = RequestMethod.PUT )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_DATA_MART_ADMIN')" )
+    public void analytics( HttpServletResponse response )
+    {
+        scheduler.executeTask( analyticsTableTask );
+        
+        ContextUtils.okResponse( response, "Initiated analytics table update" );
+    }
+
+    @RequestMapping( value = "/dataMart", method = RequestMethod.PUT )
+    @PreAuthorize( "hasRole('ALL') or hasRole('F_DATA_MART_ADMIN')" )
     public void data( HttpServletResponse response )
     {
-        analyticsTableService.update( false, null );
-        
-        ContextUtils.okResponse( response, "Initiated analytics table update" );
-    }
-
-    @RequestMapping( value = "/completeness", method = RequestMethod.PUT )
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_DATA_MART_ADMIN')" )
-    public void completeness( HttpServletResponse response )
-    {
-        completenessTableService.update( false, null );
-        
-        ContextUtils.okResponse( response, "Initiated completeness table update" );
-    }
-
-    @RequestMapping( value = "/completenessTarget", method = RequestMethod.PUT )
-    @PreAuthorize( "hasRole('ALL') or hasRole('F_DATA_MART_ADMIN')" )
-    public void completenessTarget( HttpServletResponse response )
-    {
-        completenessTargetTableService.update( false, null );
-        
-        ContextUtils.okResponse( response, "Initiated completeness target table update" );
+        scheduler.executeTask( dataMartTask );
+        
+        ContextUtils.okResponse( response, "Initiated data mart update" );
     }
     
     @RequestMapping( method = RequestMethod.PUT )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
     public void resourceTables( HttpServletResponse response )
     {
-        resourceTableService.generateAll();
+        scheduler.executeTask( resourceTableTask );
         
-        ContextUtils.okResponse( response, "All resource tables updated" );
+        ContextUtils.okResponse( response, "Initiated resource table update" );
     }
 }