use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class DnsHelpers method upload.
public void upload(TargetServer targetServer, ZoneFile zoneFile) throws OpsException {
// TODO: Validate / sanitize key
File path = new File(DnsServerTemplate.getZonesDir(), zoneFile.getKey());
String data = zoneFile.getData();
OpsTarget target = targetServer.getTarget();
String existing = target.readTextFile(path);
boolean isSame = Objects.equal(data, existing);
if (!isSame) {
// TODO: The serial value means that this is always dirty
log.info("Uploading zone file: " + path);
// Upload then atomic move
File tempFile = new File(targetServer.getTempDir(), zoneFile.getKey());
FileUpload upload = FileUpload.build(data);
upload.path = tempFile;
upload.mode = "0644";
target.doUpload(upload);
target.mv(tempFile, path);
}
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class PostgresqlServerBackup method doBackup.
@Handler(BackupAction.class)
public void doBackup() throws OpsException, IOException {
OpsContext opsContext = OpsContext.get();
// Machine machine = opsContext.getInstance(Machine.class);
OpsTarget target = opsContext.getInstance(OpsTarget.class);
// We use pg_dump, not pg_dumpall:
// 1) pg_dumpall doesn't support binary dumping (?)
// 2) pg_dumpall wouldn't let us split the dump into different files (?)
List<String> databases = listDatabases(target);
BackupContext backupContext = backups.getContext();
String baseName = UUID.randomUUID().toString();
PostgresqlServer server = OpsContext.get().getInstance(PostgresqlServer.class);
backupContext.add(new BackupItem(server.getKey(), FORMAT, baseName));
{
Command dumpAll = Command.build("su postgres -c \"pg_dumpall --globals-only\"");
Backup request = new Backup();
request.target = target;
request.objectName = baseName + "/pgdump_meta";
backupContext.uploadStream(request, dumpAll);
}
for (String database : databases) {
// template0 cannot be backed up
if (database.equals("template0")) {
continue;
}
// template1 can be backed up, even though it isn't typically very useful
String fileName = "pgdump_db_" + database;
Backup request = new Backup();
request.target = target;
request.objectName = baseName + "/" + fileName;
Command dumpDatabase = Command.build("su postgres -c \"pg_dump --oids -Fc --verbose {0}\"", database);
backupContext.uploadStream(request, dumpDatabase);
}
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class RecurseOverAll method doRecursion.
public void doRecursion(Object controller, SshKey sshKey, Class<? extends ItemBase> machineItemClass) throws OpsException {
boolean failed = false;
for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
switch(machineItem.getState()) {
case ACTIVE:
break;
case DELETED:
log.warn("Ignoring deleted server: " + machineItem);
continue;
default:
log.warn("Item not yet active: " + machineItem);
failed = true;
continue;
}
Machine machine = instances.findMachine(machineItem);
if (machine == null) {
log.warn("Server instance not found: " + machineItem);
failed = true;
continue;
}
OpsTarget target = machine.getTarget(sshKey);
try {
// Execute the children in a scope with the paired item and machine
BindingScope scope = BindingScope.push(machine, target, machineItem);
try {
OpsContext opsContext = OpsContext.get();
OperationRecursor.doRecurseChildren(opsContext, controller);
} finally {
scope.pop();
}
} catch (OpsException e) {
failed = true;
log.warn("Error updating machine: " + machine, e);
}
}
if (failed) {
throw new OpsException("Could not update all servers").setRetry(TimeSpan.ONE_MINUTE);
}
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class HdbDatabaseEntry method alreadyExists.
@Override
protected boolean alreadyExists() throws OpsException {
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
FilesystemInfo dirInfo = target.getFilesystemInfoFile(new File(getDataDirectory(), "objectClass.bdb"));
return dirInfo != null;
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class NexusApp method handler.
@Handler
public void handler() throws IOException, OpsException {
// TODO: This needs to be idempotent
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
String url = "http://nexus.sonatype.org/downloads/all/nexus-webapp-1.9.2.4.war";
File warFile = new File("/var/lib/jetty/wars/nexus-webapp-1.9.2.4.war");
target.executeCommand("wget {0} -O {1}", url, warFile);
// Whatever version of nexus we have, we want it to be the root
target.symlink(warFile, new File("/var/lib/jetty/webapps/root.war"), false);
}
Aggregations