Skip to content

Commit

Permalink
Report generation updated to limit end of report time (EUCA-3751)
Browse files Browse the repository at this point in the history
Report generation is updated to restrict the requested end time to the
current time if it is in the future.

The 'eureport-generate-report' command will now show the error message
'Invalid start or end date' if the start date is in the future.

The admin UI is updated to show errors in the status area if a start
date in the future is used or if the start time is later than the end
time. The respective error messages for these conditions are:

- Invalid report period requested, 'From' must be in the past
- Invalid report period requested, 'From' must not be later than
  'Through'

Fixes EUCA-3751.
  • Loading branch information
sjones4 committed Oct 12, 2012
1 parent 4c6047b commit f4134b6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
Expand Up @@ -32,11 +32,17 @@ public static String generateReport( @Nonnull final String type,
@Nonnull final String format,
final long start,
final long end ) throws ReportGenerationException {
final long maxEndTime = System.currentTimeMillis();
final long adjustedEndTime = end > maxEndTime ? maxEndTime : end;
if ( start >= adjustedEndTime ) {
throw new ReportGenerationArgumentException( "Invalid report period" );
}

final ReportGenerator generator = ReportGenerator.getInstance();
final ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(10240);
try {
generator.generateReport(
new Period( start, end ),
new Period( start, adjustedEndTime ),
ReportFormat.valueOf(format.toUpperCase()),
ReportType.valueOf(type.toUpperCase().replace('-','_')),
null,
Expand All @@ -48,7 +54,7 @@ public static String generateReport( @Nonnull final String type,
return new String( reportOutput.toByteArray(), Charsets.UTF_8 );
}

public static final class ReportGenerationException extends Exception {
public static class ReportGenerationException extends Exception {
private static final long serialVersionUID = 1L;

public ReportGenerationException( final String message ) {
Expand All @@ -60,4 +66,12 @@ public ReportGenerationException( final String message,
super(message, cause);
}
}

public static final class ReportGenerationArgumentException extends ReportGenerationException {
private static final long serialVersionUID = 1L;

public ReportGenerationArgumentException( final String message ) {
super(message);
}
}
}
Expand Up @@ -19,6 +19,7 @@
************************************************************************/
package com.eucalyptus.reporting.service;

import static com.eucalyptus.reporting.ReportGenerationFacade.ReportGenerationArgumentException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -135,9 +136,6 @@ public GenerateReportResponseType generateReport( final GenerateReportType reque
if ( request.getEndDate() != null ) {
endTime = parseDate( request.getEndDate() );
}
if ( endTime <= startTime ) {
throw new ReportingException( HttpResponseStatus.BAD_REQUEST, ReportingException.BAD_REQUEST, "Bad request: Invalid start or end date");
}

final String reportData;
try {
Expand All @@ -146,6 +144,8 @@ public GenerateReportResponseType generateReport( final GenerateReportType reque
Objects.firstNonNull( request.getFormat(), "html" ),
startTime,
endTime );
} catch ( final ReportGenerationArgumentException e ) {
throw new ReportingException( HttpResponseStatus.BAD_REQUEST, ReportingException.BAD_REQUEST, "Bad request: Invalid start or end date");
} catch ( final Exception e ) {
logger.error( e, e );
throw new ReportingException( HttpResponseStatus.INTERNAL_SERVER_ERROR, ReportingException.INTERNAL_SERVER_ERROR, "Error generating report");
Expand Down
Expand Up @@ -274,7 +274,7 @@ public VmTypeView getVmTypeView( ) {
@Override
public ReportView getReportView( ) {
if ( reportView == null ) {
reportView = new ReportViewImpl( );
reportView = new ReportViewImpl( this );
}
return reportView;
}
Expand Down
Expand Up @@ -65,7 +65,6 @@
import java.util.Date;

import com.eucalyptus.webui.client.ClientFactory;
import com.eucalyptus.webui.client.place.ReportPlace;
import com.eucalyptus.webui.client.view.ReportView;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
Expand Down Expand Up @@ -125,8 +124,6 @@ public void downloadHtml( ) {
private String sessionId = null;
private Date fromDate;
private Date toDate;
private String criteria;
private String groupBy;
private String type;

@Override
Expand Down
Expand Up @@ -62,13 +62,15 @@

package com.eucalyptus.webui.client.view;

import static com.google.gwt.i18n.client.DateTimeFormat.getFormat;
import static com.google.gwt.user.datepicker.client.DateBox.DefaultFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.eucalyptus.webui.client.ClientFactory;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.uibinder.client.*;
import com.google.gwt.user.client.ui.*;
Expand Down Expand Up @@ -96,20 +98,40 @@ interface ReportViewImplUiBinder extends UiBinder<Widget, ReportViewImpl> {}
ListBox type;

private Presenter presenter;

private final ClientFactory clientFactory;

private LoadingAnimationViewImpl loadingAnimation;
private Frame iFrame;

public ReportViewImpl( ) {
public ReportViewImpl( ClientFactory clientFactory ) {
this.clientFactory = clientFactory;
initWidget( uiBinder.createAndBindUi( this ) );
loadingAnimation = new LoadingAnimationViewImpl( );
iFrame = new Frame( );
this.fromDate.setFormat( new DateBox.DefaultFormat( DateTimeFormat.getFormat( PredefinedFormat.DATE_LONG ) ) );
this.toDate.setFormat( new DateBox.DefaultFormat( DateTimeFormat.getFormat( PredefinedFormat.DATE_LONG ) ) );
this.fromDate.setFormat( new DefaultFormat( getFormat( PredefinedFormat.DATE_LONG ) ) );
this.toDate.setFormat( new DefaultFormat( getFormat( PredefinedFormat.DATE_LONG ) ) );
}

@UiHandler( "generateButton" )
void handleGenerateButtonClick( ClickEvent e ) {
final Date from = fromDate.getValue( );
final Date to = toDate.getValue( );

String errorMessage = null;
if ( from == null || to == null ) {
errorMessage = "Invalid report period.";
} else if ( System.currentTimeMillis() < from.getTime() ) {
errorMessage = "Invalid report period requested, 'From' must be in the past.";
} else if ( from.getTime() > to.getTime() ) {
errorMessage = "Invalid report period requested, 'From' must not be later than 'Through'";
}

if ( errorMessage != null ) {
clientFactory.getShellView( ).getFooterView( ).showStatus(
FooterView.StatusType.ERROR, errorMessage, FooterView.DEFAULT_STATUS_CLEAR_DELAY );
return;
}

this.contentPanel.clear( );
this.contentPanel.add( loadingAnimation );
this.presenter.generateReport( fromDate.getValue( ),
Expand Down

0 comments on commit f4134b6

Please sign in to comment.