All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.operate.schema.migration.PipelineReindexPlan Maven / Gradle / Ivy

/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.operate.schema.migration;

import io.camunda.operate.exceptions.MigrationException;
import io.camunda.operate.schema.SchemaManager;
import java.util.List;
import java.util.Optional;

public abstract class PipelineReindexPlan implements ReindexPlan {

  protected List steps = List.of();
  protected String srcIndex;
  protected String dstIndex;

  @Override
  public ReindexPlan setSrcIndex(String srcIndex) {
    this.srcIndex = srcIndex;
    return this;
  }

  @Override
  public ReindexPlan setDstIndex(String dstIndex) {
    this.dstIndex = dstIndex;
    return this;
  }

  @Override
  public ReindexPlan setSteps(List steps) {
    this.steps = steps;
    return this;
  }

  @Override
  public List getSteps() {
    return steps;
  }

  protected Optional createPipelineFromSteps(final SchemaManager schemaManager)
      throws MigrationException {
    if (steps.isEmpty()) {
      return Optional.empty();
    }
    final String name = srcIndex + "-to-" + dstIndex + "-pipeline";
    final boolean added = schemaManager.addPipeline(name, getPipelineDefinition());
    if (added) {
      return Optional.of(name);
    } else {
      throw new MigrationException(String.format("Couldn't create '%s' pipeline.", name));
    }
  }

  protected abstract String getPipelineDefinition();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy