use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class BackupDirectory 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);
BackupContext backup = backups.getContext();
DirectoryBackup request = new DirectoryBackup();
request.target = target;
request.rootDirectory = backupRoot;
request.exclude.addAll(this.excludes);
backup.doBackup(request);
backup.add(new BackupItem(itemKey, FORMAT, request.objectName));
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class DnsResolverModuleBuilder method buildTemplateModel.
@Override
public void buildTemplateModel(Map<String, Object> model) throws OpsException {
List<String> nameservers = Lists.newArrayList();
for (ProviderOf<DnsResolverProvider> entry : providers.listItemsProviding(DnsResolverProvider.class)) {
DnsResolverProvider dnsResolverProvider = entry.get();
List<InetAddress> addresses = dnsResolverProvider.findAddresses(NetworkPoint.forTargetInContext());
for (InetAddress address : addresses) {
nameservers.add(address.getHostAddress());
}
}
if (nameservers.isEmpty()) {
log.warn("No (internal) resolvers found; will set up default public nameservers; reconfigure needed if this changes");
if (usePrivateResolvers) {
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
AsBlock as = AsBlock.find(target);
if (as != null) {
// We had problems with the SL resolvers...
/*
* if (Objects.equal(AsBlock.SOFTLAYER, as)) { log.warn("Adding private Softlayer resolvers");
* nameservers.add("10.0.80.11"); nameservers.add("10.0.80.12"); }
*
* if (Objects.equal(AsBlock.HETZNER, as)) { log.warn("Adding private Hetzner resolvers");
* nameservers.add("213.133.99.99"); nameservers.add("213.133.100.100");
* nameservers.add("213.133.98.98"); }
*/
}
}
nameservers.add("8.8.8.8");
nameservers.add("8.8.4.4");
nameservers.add("2001:4860:4860::8888");
nameservers.add("2001:4860:4860::8844");
// So a reconfigure is needed!
}
model.put("nameservers", nameservers);
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class SshPostgresTarget method execute.
public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
OpsTarget target = getOpsTarget();
// We probably want psql -A -t -c "command"
Command command = Command.build("psql");
command.addQuoted("--username=", username);
command.addQuoted("--host=", hostname);
command.addArgument(Argument.buildQuoted("--command=", sql).setMasked("--command=" + Command.MASKED));
CommandEnvironment env = new CommandEnvironment();
env.put("PGPASSWORD", password.plaintext());
command.setEnvironment(env);
return target.executeCommand(command);
}
use of org.platformlayer.ops.OpsTarget in project platformlayer by platformlayer.
the class ForEach method doRecursion.
public void doRecursion(Object controller, SshKey sshKey, Class<? extends ItemBase> machineItemClass, Class<? extends ItemBase> dataItemClass) throws OpsException {
boolean failed = false;
OpsContext ops = OpsContext.get();
List<ItemBase> dataItems = Lists.newArrayList();
ItemBase contextDataItem = ops.getInstance(dataItemClass);
if (contextDataItem != null) {
dataItems.add(contextDataItem);
} else {
for (ItemBase dataItem : platformLayer.listItems(dataItemClass)) {
dataItems.add(dataItem);
}
}
Object contextMachine = ops.getInstance(machineItemClass);
if (contextMachine != null) {
// We are presumably building the machine item
PlatformLayerKey targetItemKey = ops.getJobRecord().getTargetItemKey();
ItemBase machineItem = (ItemBase) contextMachine;
if (!Objects.equal(targetItemKey, machineItem.getKey())) {
throw new OpsException("Expected to find same model");
}
Machine machine = instances.findMachine(machineItem);
if (machine == null) {
log.warn("Server instance not found: " + contextMachine);
failed = true;
} else {
OpsTarget target = machine.getTarget(sshKey);
failed |= processDataItems(controller, dataItems, machineItem, machine, target);
}
} else {
// We are building a data item
for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
if (machineItem.getState() != ManagedItemState.ACTIVE) {
log.warn("Machine 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);
failed |= processDataItems(controller, dataItems, machineItem, machine, target);
}
}
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 PosixGroup method doOperation.
@Handler
public void doOperation() throws OpsException {
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
Map<String, Group> groups = PosixGroupManagement.getGroups(target);
Group group = groups.get(groupName);
if (group == null) {
target.executeCommand("groupadd {0}", groupName);
}
}
Aggregations