예제 #1
0
  private void prepareDeleteIndex(String indexerName) {
    // We do not have to take a lock on the indexer, since once in delete state the indexer cannot
    // be modified anymore by ordinary users.
    boolean canBeDeleted = false;
    try {
      // Read current situation of record and assure it is still actual
      IndexerDefinition indexer = indexerModel.getFreshIndexer(indexerName);
      if (indexer.getLifecycleState() == IndexerDefinition.LifecycleState.DELETE_REQUESTED) {
        canBeDeleted = true;

        String queueSubscriptionId = indexer.getSubscriptionId();
        if (queueSubscriptionId != null) {
          sepModel.removeSubscription(indexer.getSubscriptionId());
          // We leave the subscription ID in the indexer definition FYI
        }

        if (indexer.getActiveBatchBuildInfo() != null) {
          JobClient jobClient = getJobClient();
          String jobId = indexer.getActiveBatchBuildInfo().getJobId();
          RunningJob job = jobClient.getJob(jobId);
          if (job != null) {
            job.killJob();
            log.info("Kill indexer build job for indexer " + indexerName + ", job ID =  " + jobId);
          }
          // Just to be sure...
          jobStatusWatcher.assureWatching(
              indexer.getName(), indexer.getActiveBatchBuildInfo().getJobId());
          canBeDeleted = false;
        }

        if (!canBeDeleted) {
          indexer =
              new IndexerDefinitionBuilder()
                  .startFrom(indexer)
                  .lifecycleState(IndexerDefinition.LifecycleState.DELETING)
                  .build();
          indexerModel.updateIndexerInternal(indexer);
        }
      } else if (indexer.getLifecycleState() == IndexerDefinition.LifecycleState.DELETING) {
        // Check if the build job is already finished, if so, allow delete
        if (indexer.getActiveBatchBuildInfo() == null) {
          canBeDeleted = true;
        }
      }
    } catch (Throwable t) {
      log.error("Error preparing deletion of indexer " + indexerName, t);
    }

    if (canBeDeleted) {
      deleteIndexer(indexerName);
    }
  }
예제 #2
0
 private void unassignSubscription(String indexerName) {
   try {
     String lock = indexerModel.lockIndexer(indexerName);
     try {
       // Read current situation of record and assure it is still actual
       IndexerDefinition indexer = indexerModel.getFreshIndexer(indexerName);
       if (needsSubscriptionIdUnassigned(indexer)) {
         sepModel.removeSubscription(indexer.getSubscriptionId());
         log.info("Deleted queue subscription for indexer " + indexerName);
         indexer = new IndexerDefinitionBuilder().startFrom(indexer).subscriptionId(null).build();
         indexerModel.updateIndexerInternal(indexer);
       }
     } finally {
       indexerModel.unlockIndexer(lock);
     }
   } catch (Throwable t) {
     log.error("Error trying to delete the subscription for indexer " + indexerName, t);
   }
 }
예제 #3
0
 private boolean needsSubscriptionIdUnassigned(IndexerDefinition indexer) {
   return indexer.getIncrementalIndexingState() == IncrementalIndexingState.DO_NOT_SUBSCRIBE
       && indexer.getSubscriptionId() != null;
 }
예제 #4
0
 private boolean needsSubscriptionIdAssigned(IndexerDefinition indexer) {
   return !indexer.getLifecycleState().isDeleteState()
       && indexer.getIncrementalIndexingState() != IncrementalIndexingState.DO_NOT_SUBSCRIBE
       && indexer.getSubscriptionId() == null;
 }