private void waitForDeletion(String indexerName) throws InterruptedException, KeeperException { System.out.printf("Deleting indexer '%s'", indexerName); while (model.hasIndexer(indexerName)) { IndexerDefinition indexerDef; try { indexerDef = model.getFreshIndexer(indexerName); } catch (IndexerNotFoundException e) { // The indexer was deleted between the call to hasIndexer and getIndexer, that's ok break; } switch (indexerDef.getLifecycleState()) { case DELETE_FAILED: System.err.println("\nDelete failed"); return; case DELETE_REQUESTED: case DELETING: System.out.print("."); Thread.sleep(500); continue; default: throw new IllegalStateException("Illegal lifecycle state while deleting: " + indexerDef.getLifecycleState()); } } }
private void waitForDeletion(String indexerName) throws InterruptedException, KeeperException { System.out.printf("Deleting indexer '%s'", indexerName); while (model.hasIndexer(indexerName)) { IndexerDefinition indexerDef; try { indexerDef = model.getFreshIndexer(indexerName); } catch (IndexerNotFoundException e) { // The indexer was deleted between the call to hasIndexer and getIndexer, that's ok break; } switch (indexerDef.getLifecycleState()) { case DELETE_FAILED: System.err.println("\nDelete failed"); return; case DELETE_REQUESTED: case DELETING: System.out.print("."); Thread.sleep(500); continue; default: throw new IllegalStateException("Illegal lifecycle state while deleting: " + indexerDef.getLifecycleState()); } } System.out.printf("\nDeleted indexer '%s'\n", indexerName); }
private boolean shouldRunIndexer(IndexerDefinition indexerDef) { return indexerDef.getIncrementalIndexingState() == IncrementalIndexingState.SUBSCRIBE_AND_CONSUME && indexerDef.getSubscriptionId() != null && !indexerDef.getLifecycleState().isDeleteState(); }
private boolean needsSubscriptionIdAssigned(IndexerDefinition indexer) { return !indexer.getLifecycleState().isDeleteState() && indexer.getIncrementalIndexingState() != IncrementalIndexingState.DO_NOT_SUBSCRIBE && indexer.getSubscriptionId() == null; }
private boolean needsBatchBuildStart(IndexerDefinition indexer) { return !indexer.getLifecycleState().isDeleteState() && indexer.getBatchIndexingState() == BatchIndexingState.BUILD_REQUESTED && indexer.getActiveBatchBuildInfo() == null; }
private boolean needsSubscriptionIdAssigned(IndexerDefinition indexer) { return !indexer.getLifecycleState().isDeleteState() && indexer.getIncrementalIndexingState() != IncrementalIndexingState.DO_NOT_SUBSCRIBE && indexer.getSubscriptionId() == null; }
private boolean needsBatchBuildStart(IndexerDefinition indexer) { return !indexer.getLifecycleState().isDeleteState() && indexer.getBatchIndexingState() == BatchIndexingState.BUILD_REQUESTED && indexer.getActiveBatchBuildInfo() == null; }
private boolean shouldRunIndexer(IndexerDefinition indexerDef) { return indexerDef.getIncrementalIndexingState() == IncrementalIndexingState.SUBSCRIBE_AND_CONSUME && indexerDef.getSubscriptionId() != null && !indexerDef.getLifecycleState().isDeleteState(); }
if (indexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED || indexer.getLifecycleState() == LifecycleState.DELETING) { throw new IndexerModelException("An indexer in state " + indexer.getLifecycleState() + " cannot be locked.");
private byte[] waitForDeletion(String indexerName) throws InterruptedException, KeeperException, IndexerServerException { long startTime = System.nanoTime(); while (getModel().hasIndexer(indexerName)) { IndexerDefinition indexerDef; try { indexerDef = getModel().getFreshIndexer(indexerName); } catch (IndexerNotFoundException e) { // The indexer was deleted between the call to hasIndexer and getIndexer, that's ok break; } switch (indexerDef.getLifecycleState()) { case DELETE_FAILED: throw new IndexerServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, new IndexerDeleteFailedException("Delete of indexer " + indexerName + " failed")); case DELETE_REQUESTED: case DELETING: Thread.sleep(500); // timer at the end so we try at least once if (TimeUnit.MILLISECONDS.toNanos(DELETE_TIMEOUT_MILLIS) < System.nanoTime() - startTime) { throw new IndexerServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, new IndexerDeleteFailedException("Delete of indexer " + indexerName + " timed out")); } continue; default: throw new IllegalStateException("Illegal lifecycle state while deleting: " + indexerDef.getLifecycleState()); } } return toJsonResultBytes("Deleted indexer \'" + indexerName + "\'"); }
@Override protected void run(OptionSet options) throws Exception { super.run(options); String indexerName = nameOption.value(options); if (!model.hasIndexer(indexerName)) { throw new CliException("Indexer does not exist: " + indexerName); } IndexerDefinition indexerDef = model.getIndexer(indexerName); if (indexerDef.getLifecycleState() == LifecycleState.DELETE_REQUESTED || indexerDef.getLifecycleState() == LifecycleState.DELETING) { System.err.printf("Delete of '%s' is already in progress\n", indexerName); return; } IndexerDefinitionBuilder builder = new IndexerDefinitionBuilder(); builder.startFrom(indexerDef); builder.lifecycleState(LifecycleState.DELETE_REQUESTED); model.updateIndexerInternal(builder.build()); waitForDeletion(indexerName); }
@Override protected void run(OptionSet options) throws Exception { super.run(options); String indexerName = nameOption.value(options); if (!options.has("http")) { if (!model.hasIndexer(indexerName)) { throw new CliException("Indexer does not exist: " + indexerName); } IndexerDefinition indexerDef = model.getIndexer(indexerName); if (indexerDef.getLifecycleState() == LifecycleState.DELETE_REQUESTED || indexerDef.getLifecycleState() == LifecycleState.DELETING) { System.err.printf("Delete of '%s' is already in progress\n", indexerName); return; } IndexerDefinitionBuilder builder = new IndexerDefinitionBuilder(); builder.startFrom(indexerDef); builder.lifecycleState(LifecycleState.DELETE_REQUESTED); model.updateIndexerInternal(builder.build()); waitForDeletion(indexerName); System.out.printf("\nDeleted indexer '%s'\n", indexerName); } else { deleteIndexerHttp(options, indexerName); } }
if (currentIndexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED || currentIndexer.getLifecycleState() == LifecycleState.DELETING) { throw new IndexerUpdateException("An indexer in state " + indexer.getLifecycleState() + " cannot be modified."); if (currentIndexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED) { throw new IndexerUpdateException("An indexer in the state " + LifecycleState.DELETE_REQUESTED + " cannot be updated.");
if (currentIndexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED || currentIndexer.getLifecycleState() == LifecycleState.DELETING) { throw new IndexerUpdateException("An indexer in state " + indexer.getLifecycleState() + " cannot be modified."); if (currentIndexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED) { throw new IndexerUpdateException("An indexer in the state " + LifecycleState.DELETE_REQUESTED + " cannot be updated.");
IndexerDefinition indexerDef = getModel().getIndexer(indexerName); if (indexerDef.getLifecycleState() == LifecycleState.DELETE_REQUESTED || indexerDef.getLifecycleState() == LifecycleState.DELETING) { throw new IndexerServerException(HttpServletResponse.SC_BAD_REQUEST, new IndexerConcurrentModificationException("Delete of \'" + indexerName + "\' is already in progress"));
&& newIndexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED; model.unlockIndexer(lock, ignoreMissing);
public void run(OptionSet options) throws Exception { super.run(options); String indexName = nameOption.value(options); if (!options.has("http")) { if (!model.hasIndexer(indexName)) { throw new CliException("Indexer does not exist: " + indexName); } IndexerDefinition newIndexer = null; String lock = model.lockIndexer(indexName); try { IndexerDefinition indexer = model.getFreshIndexer(indexName); IndexerDefinitionBuilder builder = buildIndexerDefinition(options, indexer); newIndexer = builder.build(); if (newIndexer.equals(indexer)) { System.out.println("Index already matches the specified settings, did not update it."); } else { model.updateIndexer(newIndexer, lock); System.out.println("Index updated: " + indexName); } } finally { // In case we requested deletion of an index, it might be that the lock is already removed // by the time we get here as part of the index deletion. boolean ignoreMissing = newIndexer != null && newIndexer.getLifecycleState() == LifecycleState.DELETE_REQUESTED; model.unlockIndexer(lock, ignoreMissing); } } else { updateIndexerHttp(options, indexName); } }
public IndexerDefinitionBuilder startFrom(IndexerDefinition existingDefinition) { this.name = existingDefinition.getName(); this.lifecycleState = existingDefinition.getLifecycleState(); this.batchIndexingState = existingDefinition.getBatchIndexingState(); this.incrementalIndexingState = existingDefinition.getIncrementalIndexingState(); this.subscriptionId = existingDefinition.getSubscriptionId(); this.configuration = existingDefinition.getConfiguration(); this.indexerComponentFactory = existingDefinition.getIndexerComponentFactory(); this.connectionType = existingDefinition.getConnectionType(); this.connectionParams = existingDefinition.getConnectionParams(); this.defaultBatchIndexCliArguments = existingDefinition.getDefaultBatchIndexCliArguments(); this.batchIndexCliArguments = existingDefinition.getBatchIndexCliArguments(); this.lastBatchBuildInfo = existingDefinition.getLastBatchBuildInfo(); this.activeBatchBuildInfo = existingDefinition.getActiveBatchBuildInfo(); this.subscriptionTimestamp = existingDefinition.getSubscriptionTimestamp(); this.occVersion = existingDefinition.getOccVersion(); return this; }
public IndexerDefinitionBuilder startFrom(IndexerDefinition existingDefinition) { this.name = existingDefinition.getName(); this.lifecycleState = existingDefinition.getLifecycleState(); this.batchIndexingState = existingDefinition.getBatchIndexingState(); this.incrementalIndexingState = existingDefinition.getIncrementalIndexingState(); this.subscriptionId = existingDefinition.getSubscriptionId(); this.configuration = existingDefinition.getConfiguration(); this.indexerComponentFactory = existingDefinition.getIndexerComponentFactory(); this.connectionType = existingDefinition.getConnectionType(); this.connectionParams = existingDefinition.getConnectionParams(); this.defaultBatchIndexCliArguments = existingDefinition.getDefaultBatchIndexCliArguments(); this.batchIndexCliArguments = existingDefinition.getBatchIndexCliArguments(); this.lastBatchBuildInfo = existingDefinition.getLastBatchBuildInfo(); this.activeBatchBuildInfo = existingDefinition.getActiveBatchBuildInfo(); this.subscriptionTimestamp = existingDefinition.getSubscriptionTimestamp(); this.occVersion = existingDefinition.getOccVersion(); return this; }
node.put("lifecycleState", indexer.getLifecycleState().toString()); node.put("batchIndexingState", indexer.getBatchIndexingState().toString()); node.put("incrementalIndexingState", indexer.getIncrementalIndexingState().toString());