public BackupSchemaStep( String daemon, CassandraState cassandraState, CassandraOfferRequirementProvider provider, BackupRestoreContext context) { super(daemon, BackupSchemaTask.nameForDaemon(daemon), cassandraState, provider); this.context = context; }
@Override public BackupSchemaTask updateId() { return new BackupSchemaTask(getBuilder().setTaskId(createId(getName())) .build()); }
/** * Constructs a BackupSchema. * @param driver The ExecutorDriver used to send task status. * @param daemon The CassandraDaemonProcess used to fetch schema. * @param cassandraTask The CassandraTask that will be executed by the * BackupSchema. */ public BackupSchema(ExecutorDriver driver, CassandraDaemonProcess daemon, BackupSchemaTask cassandraTask, BackupStorageDriver backupStorageDriver) { this.daemon = daemon; this.driver = driver; this.cassandraTask = cassandraTask; this.backupStorageDriver = backupStorageDriver; context = cassandraTask.getBackupRestoreContext(); }
@Override public BackupSchemaTask update(Protos.TaskState state) { return new BackupSchemaTask(getBuilder().setData( getData().withState(state).getBytes()).build()); }
public static BackupSchemaTask create( final Protos.TaskInfo template, final CassandraDaemonTask daemon, final BackupRestoreContext context) { String name = nameForDaemon(daemon); CassandraData data = CassandraData.createBackupSchemaData( "", context .forNode(daemon.getName()) .withLocalLocation(daemon.getVolumePath() + "/data")); Protos.TaskInfo completedTemplate = Protos.TaskInfo.newBuilder(template) .setName(name) .setTaskId(TaskUtils.toTaskId(name)) .setData(data.getBytes()) .build(); completedTemplate = org.apache.mesos.offer.TaskUtils.clearTransient(completedTemplate); return new BackupSchemaTask(completedTemplate); }
previousBackupTasks.put("hi", BackupSnapshotTask.parse(TaskInfo.getDefaultInstance())); Map<String, BackupSchemaTask> previousSchemaTasks = new HashMap<>(); previousSchemaTasks.put("hello", BackupSchemaTask.parse(TaskInfo.getDefaultInstance())); when(mockCassandraState.getBackupUploadTasks()).thenReturn(previousUploadTasks); when(mockCassandraState.getBackupSnapshotTasks()).thenReturn(previousBackupTasks);
public static BackupSchemaTask parse(final Protos.TaskInfo info) { return new BackupSchemaTask(info); }
public BackupRestoreContext getBackupRestoreContext() { return getData().getBackupRestoreContext(); } }
public BackupSchemaTask createBackupSchemaTask( CassandraDaemonTask daemon, BackupRestoreContext context) throws PersistenceException { Optional<Protos.TaskInfo> template = getTemplate(daemon); if (template.isPresent()) { return BackupSchemaTask.create(template.get(), daemon, context); } else { throw new PersistenceException("Failed to retrieve ClusterTask Template."); } }
private void sendStatus(ExecutorDriver driver, Protos.TaskState state, String message) { final Protos.TaskStatus status = cassandraTask.createStatus(state,Optional.of(message)).getTaskStatus(); driver.sendStatusUpdate(status); }
@Override public BackupSchemaTask update(Protos.Offer offer) { return new BackupSchemaTask(getBuilder() .setSlaveId(offer.getSlaveId()) .setData(getData().withHostname(offer.getHostname()).getBytes()) .build()); }
return BackupSnapshotTask.parse(info); case BACKUP_SCHEMA: return BackupSchemaTask.parse(info); case BACKUP_UPLOAD: return BackupUploadTask.parse(info);
/** * Gets the name of a BackupSchemaTask for a CassandraDaemonTask. * * @param daemon The CassandraDaemonTask for which the schema will be * backed up. * @return The name of the BackupSchemaTask for daemon. */ public static final String nameForDaemon(final CassandraDaemonTask daemon) { return nameForDaemon(daemon.getName()); }
public static BackupStorageDriver createStorageDriver(CassandraTask cassandraTask) { String externalLocation = null; switch (cassandraTask.getType()) { case BACKUP_SNAPSHOT: externalLocation = ((BackupUploadTask)cassandraTask).getBackupRestoreContext().getExternalLocation(); break; case BACKUP_SCHEMA: externalLocation = ((BackupSchemaTask)cassandraTask).getBackupRestoreContext().getExternalLocation(); break; case SCHEMA_RESTORE: externalLocation = ((RestoreSchemaTask)cassandraTask).getBackupRestoreContext().getExternalLocation(); break; case SNAPSHOT_DOWNLOAD: externalLocation = ((DownloadSnapshotTask)cassandraTask).getBackupRestoreContext().getExternalLocation(); break; } return getBackupStorageDriver(externalLocation); }
public BackupSchemaTask getOrCreateBackupSchema( CassandraDaemonTask daemon, BackupRestoreContext context) throws PersistenceException { String name = BackupSchemaTask.nameForDaemon(daemon); Map<String, BackupSchemaTask> schemas = getBackupSchemaTasks(); if (schemas.containsKey(name)) { return schemas.get(name); } else { return createBackupSchemaTask(daemon, context); } }