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

Commit

Permalink
rhbz1065790 rename ReindexAsyncBean to SearchIndexManager and move to…
Browse files Browse the repository at this point in the history
… service package
  • Loading branch information
davidmason committed Feb 19, 2014
1 parent 47fed47 commit ee4c7aa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
53 changes: 27 additions & 26 deletions zanata-war/src/main/java/org/zanata/action/ReindexActionBean.java
Expand Up @@ -18,6 +18,7 @@
import org.joda.time.format.PeriodFormatterBuilder;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.TimedAsyncHandle;
import org.zanata.service.SearchIndexManager;

import com.google.common.base.Optional;

Expand All @@ -30,22 +31,22 @@ public class ReindexActionBean implements Serializable {
private static final long serialVersionUID = 1L;

@In
ReindexAsyncBean reindexAsync;
SearchIndexManager searchIndexManager;

public List<ReindexClassOptions> getClasses() {
return reindexAsync.getReindexOptions();
return searchIndexManager.getReindexOptions();
}

public void selectAll(boolean selected) {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
opts.setPurge(selected);
opts.setReindex(selected);
opts.setOptimize(selected);
}
}

public boolean isPurgeAll() {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
if (!opts.isPurge()) {
return false;
}
Expand All @@ -54,13 +55,13 @@ public boolean isPurgeAll() {
}

public void setPurgeAll(boolean selected) {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
opts.setPurge(selected);
}
}

public boolean isReindexAll() {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
if (!opts.isReindex()) {
return false;
}
Expand All @@ -69,13 +70,13 @@ public boolean isReindexAll() {
}

public void setReindexAll(boolean selected) {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
opts.setReindex(selected);
}
}

public boolean isOptimizeAll() {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
if (!opts.isOptimize()) {
return false;
}
Expand All @@ -84,26 +85,26 @@ public boolean isOptimizeAll() {
}

public void setOptimizeAll(boolean selected) {
for (ReindexClassOptions opts : reindexAsync.getReindexOptions()) {
for (ReindexClassOptions opts : searchIndexManager.getReindexOptions()) {
opts.setOptimize(selected);
}
}

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

public boolean isInProgress() {
return reindexAsync.getProcessHandle() != null
&& !reindexAsync.getProcessHandle().isDone();
return searchIndexManager.getProcessHandle() != null
&& !searchIndexManager.getProcessHandle().isDone();
}

public String getCurrentClass() {
return reindexAsync.getCurrentClassName();
return searchIndexManager.getCurrentClassName();
}

public boolean isError() {
AsyncTaskHandle<Void> taskHandle = reindexAsync.getProcessHandle();
AsyncTaskHandle<Void> taskHandle = searchIndexManager.getProcessHandle();
if (taskHandle == null) {
return false;
} else if (taskHandle.isDone()) {
Expand All @@ -121,35 +122,35 @@ public boolean isError() {
}

public int getReindexCount() {
if (reindexAsync.getProcessHandle() == null) {
if (searchIndexManager.getProcessHandle() == null) {
return 0;
} else {
return reindexAsync.getProcessHandle().getMaxProgress();
return searchIndexManager.getProcessHandle().getMaxProgress();
}
}

public int getReindexProgress() {
if (reindexAsync.getProcessHandle() == null) {
if (searchIndexManager.getProcessHandle() == null) {
return 0;
} else {
return reindexAsync.getProcessHandle().getCurrentProgress();
return searchIndexManager.getProcessHandle().getCurrentProgress();
}
}

public void reindexDatabase() {
if (reindexAsync.getProcessHandle() == null
|| reindexAsync.getProcessHandle().isDone()) {
reindexAsync.startProcess();
if (searchIndexManager.getProcessHandle() == null
|| searchIndexManager.getProcessHandle().isDone()) {
searchIndexManager.startProcess();
}
}

public void cancel() {
reindexAsync.getProcessHandle().cancel();
searchIndexManager.getProcessHandle().cancel();
}

public boolean isCanceled() {
return reindexAsync.getProcessHandle() != null
&& reindexAsync.getProcessHandle().isCancelled();
return searchIndexManager.getProcessHandle() != null
&& searchIndexManager.getProcessHandle().isCancelled();
}

// TODO move to common location with ViewAllStatusAction
Expand All @@ -172,7 +173,7 @@ private String formatTimePeriod(long durationInMillis) {
}

public String getElapsedTime() {
TimedAsyncHandle<Void> processHandle = reindexAsync.getProcessHandle();
TimedAsyncHandle<Void> processHandle = searchIndexManager.getProcessHandle();
if (processHandle == null) {
log.error("processHandle is null when looking up elapsed time");
return "";
Expand All @@ -183,7 +184,7 @@ public String getElapsedTime() {
}

public String getEstimatedTimeRemaining() {
Optional<Long> estimate = reindexAsync.getProcessHandle().getEstimatedTimeRemaining();
Optional<Long> estimate = searchIndexManager.getProcessHandle().getEstimatedTimeRemaining();
if (estimate.isPresent()) {
return formatTimePeriod(estimate.get());
}
Expand Down
@@ -1,4 +1,4 @@
package org.zanata.action;
package org.zanata.service;

import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -20,6 +20,7 @@
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.Synchronized;
import org.zanata.ServerConstants;
import org.zanata.action.ReindexClassOptions;
import org.zanata.async.AsyncTask;
import org.zanata.async.AsyncTaskHandle;
import org.zanata.async.TimedAsyncHandle;
Expand All @@ -34,14 +35,13 @@
import org.zanata.search.ClassIndexer;
import org.zanata.search.HTextFlowTargetIndexingStrategy;
import org.zanata.search.SimpleClassIndexingStrategy;
import org.zanata.service.AsyncTaskManagerService;

@Name("reindexAsync")
@Name("searchIndexManager")
@Scope(ScopeType.APPLICATION)
@Startup
@Synchronized(timeout = ServerConstants.DEFAULT_TIMEOUT)
@Slf4j
public class ReindexAsyncBean implements Serializable {
public class SearchIndexManager implements Serializable {
private static final long serialVersionUID = 1L;

@In
Expand Down
Expand Up @@ -26,9 +26,9 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.security.Restrict;
import org.zanata.action.ReindexAsyncBean;
import org.zanata.exception.ZanataServiceException;
import org.zanata.rest.dto.ReindexStatus;
import org.zanata.service.SearchIndexManager;
import org.zanata.service.SearchService;

/**
Expand All @@ -43,18 +43,18 @@
@Restrict("#{s:hasRole('admin')}")
public class SearchServiceImpl implements SearchService {
@In
private ReindexAsyncBean reindexAsync;
private SearchIndexManager searchIndexManager;

@Override
public ReindexStatus startReindex(@QueryParam("purge") boolean purgeAll,
@QueryParam("index") boolean indexAll,
@QueryParam("optimize") boolean optimizeAll) {
reindexAsync.setOptions(purgeAll, indexAll, optimizeAll);
searchIndexManager.setOptions(purgeAll, indexAll, optimizeAll);
boolean startedReindex = false;

if (reindexAsync.getProcessHandle().isDone()) {
if (searchIndexManager.getProcessHandle().isDone()) {
startedReindex = true;
reindexAsync.startProcess();
searchIndexManager.startProcess();
}

ReindexStatus status = this.getReindexStatus();
Expand All @@ -64,21 +64,21 @@ public ReindexStatus startReindex(@QueryParam("purge") boolean purgeAll,

@Override
public ReindexStatus getReindexStatus() {
if (reindexAsync.getProcessHandle().isDone()) {
if (searchIndexManager.getProcessHandle().isDone()) {
throw new ZanataServiceException(
"Reindexing not in currently in progress", 404);
}

ReindexStatus status = new ReindexStatus();
status.setCurrentElementType(reindexAsync.getCurrentClassName());
status.setIndexedElements(reindexAsync.getProcessHandle()
status.setCurrentElementType(searchIndexManager.getCurrentClassName());
status.setIndexedElements(searchIndexManager.getProcessHandle()
.getCurrentProgress());
status.setTotalElements(reindexAsync.getProcessHandle()
status.setTotalElements(searchIndexManager.getProcessHandle()
.getMaxProgress());
// TODO This service is currently not being used
// To re-add these properties, just implement TimedAsyncHandle
// status.setTimeElapsed(reindexAsync.getProcessHandle().getElapsedTime());
// status.setTimeRemaining(reindexAsync.getProcessHandle().getEstimatedTimeRemaining());
// status.setTimeElapsed(searchIndexManager.getProcessHandle().getElapsedTime());
// status.setTimeRemaining(searchIndexManager.getProcessHandle().getEstimatedTimeRemaining());

return status;
}
Expand Down

0 comments on commit ee4c7aa

Please sign in to comment.