// Path: src/main/java/org/arbeitspferde/groningen/Datastore.java
// class DatastoreException extends Exception {
//   public DatastoreException() {
//     super();
//   }
//     
//   public DatastoreException(final String message) {
//     super(message);
//   }
//     
//   public DatastoreException(final Throwable cause) {
//     super(cause);
//   }
//     
//   public DatastoreException(final String message, final Throwable cause) {
//     super(message, cause);
//   }
// }
// 
// Path: src/main/java/org/arbeitspferde/groningen/config/DatastoreConfigManager.java
// public class DatastoreConfigManager implements ConfigManager {
//   private final Datastore dataStore;
//   private final PipelineId pipelineId;
// 
//   public DatastoreConfigManager(Datastore dataStore, PipelineId pipelineId) {
//     this.dataStore = dataStore;
//     this.pipelineId = pipelineId;
//   }
// 
//   @Override
//   public void initialize() {
//   }
// 
//   @Override
//   public void shutdown() {
//   }
// 
//   @Override
//   public GroningenConfig queryConfig() {
//     List<PipelineState> states;
//     try {
//       states = dataStore.getPipelines(Lists.newArrayList(pipelineId));
//     } catch (DatastoreException e) {
//       throw new RuntimeException(e);
//     }
// 
//     if (states.isEmpty()) {
//       throw new RuntimeException("No state found.");
//     } else {
//       return states.get(0).config();
//     }
//   }
// }


import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.arbeitspferde.groningen.Datastore.DatastoreException;
import org.arbeitspferde.groningen.config.DatastoreConfigManager;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
package org.arbeitspferde.groningen;




/**
 * PipelineRestorer queries the datastore for the pipelines belonging to the current shard. Then it
 * starts them via {@link PipelineManager}.
 */
public class PipelineRestorer {
  private static final Logger log = Logger.getLogger(PipelineRestorer.class.getCanonicalName());

  private final Integer shardIndex;
  private final Datastore dataStore;
  private final PipelineManager pipelineManager;
  private final PipelineIdGenerator pipelineIdGenerator;

  @Inject
  public PipelineRestorer(@Named("shardIndex") Integer shardIndex, Datastore dataStore,
      PipelineManager pipelineManager, PipelineIdGenerator pipelineIdGenerator) {
        this.shardIndex = shardIndex;
        this.dataStore = dataStore;
        this.pipelineManager = pipelineManager;
        this.pipelineIdGenerator = pipelineIdGenerator;
  }

  public void restorePipelines() {
    List<PipelineId> currentShardIds = new ArrayList<>();
    List<PipelineId> allPipelinesIds;
    try {
      allPipelinesIds = dataStore.listPipelinesIds();
// Path: src/main/java/org/arbeitspferde/groningen/Datastore.java
// class DatastoreException extends Exception {
//   public DatastoreException() {
//     super();
//   }
//     
//   public DatastoreException(final String message) {
//     super(message);
//   }
//     
//   public DatastoreException(final Throwable cause) {
//     super(cause);
//   }
//     
//   public DatastoreException(final String message, final Throwable cause) {
//     super(message, cause);
//   }
// }
// 
// Path: src/main/java/org/arbeitspferde/groningen/config/DatastoreConfigManager.java
// public class DatastoreConfigManager implements ConfigManager {
//   private final Datastore dataStore;
//   private final PipelineId pipelineId;
// 
//   public DatastoreConfigManager(Datastore dataStore, PipelineId pipelineId) {
//     this.dataStore = dataStore;
//     this.pipelineId = pipelineId;
//   }
// 
//   @Override
//   public void initialize() {
//   }
// 
//   @Override
//   public void shutdown() {
//   }
// 
//   @Override
//   public GroningenConfig queryConfig() {
//     List<PipelineState> states;
//     try {
//       states = dataStore.getPipelines(Lists.newArrayList(pipelineId));
//     } catch (DatastoreException e) {
//       throw new RuntimeException(e);
//     }
// 
//     if (states.isEmpty()) {
//       throw new RuntimeException("No state found.");
//     } else {
//       return states.get(0).config();
//     }
//   }
// }


// Path: src/main/java/org/arbeitspferde/groningen/PipelineRestorer.java
import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.arbeitspferde.groningen.Datastore.DatastoreException;
import org.arbeitspferde.groningen.config.DatastoreConfigManager;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

package org.arbeitspferde.groningen;




/**
 * PipelineRestorer queries the datastore for the pipelines belonging to the current shard. Then it
 * starts them via {@link PipelineManager}.
 */
public class PipelineRestorer {
  private static final Logger log = Logger.getLogger(PipelineRestorer.class.getCanonicalName());

  private final Integer shardIndex;
  private final Datastore dataStore;
  private final PipelineManager pipelineManager;
  private final PipelineIdGenerator pipelineIdGenerator;

  @Inject
  public PipelineRestorer(@Named("shardIndex") Integer shardIndex, Datastore dataStore,
      PipelineManager pipelineManager, PipelineIdGenerator pipelineIdGenerator) {
        this.shardIndex = shardIndex;
        this.dataStore = dataStore;
        this.pipelineManager = pipelineManager;
        this.pipelineIdGenerator = pipelineIdGenerator;
  }

  public void restorePipelines() {
    List<PipelineId> currentShardIds = new ArrayList<>();
    List<PipelineId> allPipelinesIds;
    try {
      allPipelinesIds = dataStore.listPipelinesIds();
    } catch (DatastoreException e) {