Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz1065790 display time and estimate for reindex action
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Feb 18, 2014
1 parent 88c5ee3 commit f8de65a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
45 changes: 33 additions & 12 deletions zanata-war/src/main/java/org/zanata/action/ReindexActionBean.java
Expand Up @@ -5,6 +5,8 @@
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import lombok.extern.slf4j.Slf4j;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
Expand All @@ -15,9 +17,13 @@
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.TimedAsyncHandle;

import com.google.common.base.Optional;

@AutoCreate
@Name("reindexAction")
@Slf4j
@Scope(ScopeType.STATELESS)
@Restrict("#{s:hasRole('admin')}")
public class ReindexActionBean implements Serializable {
Expand Down Expand Up @@ -83,6 +89,10 @@ public void setOptimizeAll(boolean selected) {
}
}

public boolean isReindexedSinceServerRestart() {
return reindexAsync.getProcessHandle() != null;
}

public boolean isInProgress() {
return reindexAsync.getProcessHandle() != null
&& !reindexAsync.getProcessHandle().isDone();
Expand Down Expand Up @@ -143,30 +153,41 @@ public boolean isCanceled() {
}

// TODO move to common location with ViewAllStatusAction
private static final PeriodFormatterBuilder PERIOD_FORMATTER_BUILDER =
private static final PeriodFormatter PERIOD_FORMATTER =
new PeriodFormatterBuilder().appendDays()
.appendSuffix(" day", " days").appendSeparator(", ")
.appendHours().appendSuffix(" hour", " hours")
.appendSeparator(", ").appendMinutes()
.appendSuffix(" min", " mins");
.appendSuffix(" min", " mins")
.toFormatter();

private String formatTimePeriod(long durationInMillis) {
PeriodFormatter formatter = PERIOD_FORMATTER_BUILDER.toFormatter();
Period period = new Period(durationInMillis);

if (period.toStandardMinutes().getMinutes() <= 0) {
return "less than a minute"; // TODO Localize
} else {
return formatter.print(period.normalizedStandard());
return PERIOD_FORMATTER.print(period.normalizedStandard());
}
}

public String getElapsedTime() {
TimedAsyncHandle<Boolean> processHandle = reindexAsync.getProcessHandle();
if (processHandle == null) {
log.error("processHandle is null when looking up elapsed time");
return "";
} else {
long elapsedTime = processHandle.getElapsedTime();
return formatTimePeriod(elapsedTime);
}
}

/*
* public String getElapsedTime() { return
* formatTimePeriod(reindexAsync.getProcessHandle().getElapsedTime()); }
*
* public String getEstimatedTimeRemaining() { return
* formatTimePeriod(reindexAsync
* .getProcessHandle().getEstimatedTimeRemaining()); }
*/
public String getEstimatedTimeRemaining() {
Optional<Long> estimate = reindexAsync.getProcessHandle().getEstimatedTimeRemaining();
if (estimate.isPresent()) {
return formatTimePeriod(estimate.get());
}
// TODO localize (not expecting to display estimate when it is unavailable anyway).
return "unknown";
}
}
Expand Up @@ -200,6 +200,7 @@ public Boolean call() throws Exception {
log.info("Reindexing aborted because there are no actions to perform (may be indexing an empty table)");
return null;
}
getHandle().startTiming();
for (Class<?> clazz : indexables) {
if (!getHandle().isCancelled()
&& indexingOptions.get(clazz).isPurge()) {
Expand Down Expand Up @@ -240,6 +241,7 @@ public Boolean call() throws Exception {

log.info("Re-indexing finished");
}
getHandle().finishTiming();
return true;
}
}
Expand Down
Expand Up @@ -75,7 +75,7 @@
public class ViewAllStatusAction implements Serializable {
private static final long serialVersionUID = 1L;

// Period Formatters are thread safe and immutableaccording to joda time
// Period Formatters are thread safe and immutable according to joda time
// docs
private static final PeriodFormatter COPY_TRANS_TIME_REMAINING_FORMATTER =
new PeriodFormatterBuilder().appendDays()
Expand Down
4 changes: 2 additions & 2 deletions zanata-war/src/main/resources/messages.properties
Expand Up @@ -742,8 +742,8 @@ jsf.ManageSearch.SelectNone=Clear Selection
jsf.ManageSearch.PerformSelectedActions=Perform Selected Actions
jsf.ManageSearch.CurrentProgress=Current Progress
jsf.ManageSearch.NoOperationsRunning=No operations are running
jsf.ManageSearch.Completed=Completed successfully
jsf.ManageSearch.Aborted=Aborted by user
jsf.ManageSearch.Completed=Completed successfully (ran for #{reindexAction.elapsedTime})
jsf.ManageSearch.Aborted=Aborted by user (ran for #{reindexAction.elapsedTime})
jsf.manageSearch.ErrorMessage=Due to an error, some objects could not be reindexed. See server log for details.
jsf.manageSearch.PleaseReindex=Please reindex again to ensure the search index is up-to-date.
jsf.manageSearch.ProgressMessage=#{reindexAction.reindexProgress} of #{reindexAction.reindexCount} operations complete
Expand Down
16 changes: 5 additions & 11 deletions zanata-war/src/main/webapp/admin/search.xhtml
Expand Up @@ -135,12 +135,9 @@
<p><h:outputText escape="false"
value="#{messages['jsf.ManageSearch.NoOperationsRunning']}" /></p>
</s:fragment>
<ui:remove>
<!-- FIXME this shows even if no reindex has been done at all. -->
<s:fragment rendered="#{!reindexAction.inProgress and !reindexAction.canceled and !reindexAction.error}">
<p><h:outputText value="#{messages['jsf.ManageSearch.Completed']}" /></p>
</s:fragment>
</ui:remove>
<s:fragment rendered="#{reindexAction.reindexedSinceServerRestart and !reindexAction.inProgress and !reindexAction.canceled and !reindexAction.error}">
<p><h:outputText value="#{messages['jsf.ManageSearch.Completed']}" /></p>
</s:fragment>
<s:fragment rendered="#{reindexAction.canceled}">
<p><h:outputText escape="false" value="#{messages['jsf.ManageSearch.Aborted']}" /></p>
</s:fragment>
Expand Down Expand Up @@ -172,13 +169,10 @@
<s:fragment rendered="#{reindexAction.inProgress || reindexAction.canceled || reindexAction.error}">
<p><h:outputText value="#{messages['jsf.manageSearch.CurrentTable']}" /></p>
</s:fragment>
<ui:remove>
<!-- FIXME action bean needs to be updated with working methods for elapsed and remaining time -->
<s:fragment rendered="#{reindexAction.inProgress}">
<s:fragment rendered="#{reindexAction.inProgress}">
<p><h:outputText value="#{messages['jsf.ManageSearch.ElapsedTime']}" /></p>
<p><h:outputText value="#{messages['jsf.ManageSearch.RemainingTime']}" /></p>
</s:fragment>
</ui:remove>
</s:fragment>
</a4j:outputPanel>

<a4j:commandButton id="cancel"
Expand Down

0 comments on commit f8de65a

Please sign in to comment.