// 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;
  }

  public void restorePipelines() {
    List<PipelineId> currentShardIds = new ArrayList<>();
    List<PipelineId> allPipelinesIds;
    try {
      allPipelinesIds = dataStore.listPipelinesIds();
    } catch (DatastoreException e) {
      log.log(Level.SEVERE, "can't list pipelines in datastore: " + e.getMessage(), e);
      throw new RuntimeException(e);
    }

    for (PipelineId id : allPipelinesIds) {
      if (pipelineIdGenerator.shardIndexForPipelineId(id) == shardIndex) {
        currentShardIds.add(id);
      }
    }
    log.info(String.format("%d out of %d stored pipelines belong to me (shard %d).",
        currentShardIds.size(), allPipelinesIds.size(), shardIndex));

    List<PipelineState> states;
    try {
      states = dataStore.getPipelines(currentShardIds);
    } catch (DatastoreException e) {
      log.log(Level.SEVERE, "can't get pipelines in datastore: " + e.getMessage(), e);
      throw new RuntimeException(e);
    }

    for (PipelineState state : states) {
      pipelineManager.restorePipeline(state,
// 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;

  }

  public void restorePipelines() {
    List<PipelineId> currentShardIds = new ArrayList<>();
    List<PipelineId> allPipelinesIds;
    try {
      allPipelinesIds = dataStore.listPipelinesIds();
    } catch (DatastoreException e) {
      log.log(Level.SEVERE, "can't list pipelines in datastore: " + e.getMessage(), e);
      throw new RuntimeException(e);
    }

    for (PipelineId id : allPipelinesIds) {
      if (pipelineIdGenerator.shardIndexForPipelineId(id) == shardIndex) {
        currentShardIds.add(id);
      }
    }
    log.info(String.format("%d out of %d stored pipelines belong to me (shard %d).",
        currentShardIds.size(), allPipelinesIds.size(), shardIndex));

    List<PipelineState> states;
    try {
      states = dataStore.getPipelines(currentShardIds);
    } catch (DatastoreException e) {
      log.log(Level.SEVERE, "can't get pipelines in datastore: " + e.getMessage(), e);
      throw new RuntimeException(e);
    }

    for (PipelineState state : states) {
      pipelineManager.restorePipeline(state,
          new DatastoreConfigManager(dataStore, state.pipelineId()), false);