use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class SolrClusterController method getMachines.
@Override
public List<Machine> getMachines(boolean required) throws OpsException {
Filter parentFilter = TagFilter.byTag(Tag.buildParentTag(model.getKey()));
List<Machine> machines = Lists.newArrayList();
for (SolrServer server : platformLayer.listItems(SolrServer.class, parentFilter)) {
Machine machine = instances.getMachine(server, required);
if (machine != null) {
machines.add(machine);
}
}
return machines;
}
use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class MysqlConnection method doRecurseOperation.
@Override
public void doRecurseOperation() throws OpsException {
MysqlServer mysqlServer = platformLayerHelpers.getItem(key, MysqlServer.class);
String username = this.username;
if (username == null) {
username = "root";
password = mysqlServer.rootPassword;
}
Machine machine = instanceHelpers.getMachine(mysqlServer);
String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext());
MysqlTarget mysql = new MysqlTarget(address, username, password);
BindingScope scope = BindingScope.push(mysql);
try {
OpsContext opsContext = OpsContext.get();
OperationRecursor.doRecurseChildren(opsContext, this);
} finally {
scope.pop();
}
}
use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class NginxFrontendDns method buildItemTemplate.
@Override
protected DnsRecord buildItemTemplate() throws OpsException {
// TODO: Idempotency etc
// Machine machine = OpsContext.get().getInstance(Machine.class);
NginxService nginxService = OpsContext.get().getInstance(NginxService.class);
NginxFrontend nginxFrontend = OpsContext.get().getInstance(NginxFrontend.class);
Machine machine = instanceHelpers.getMachine(nginxService);
String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forPublicInternet());
DnsRecord record = new DnsRecord();
record.setDnsName(nginxFrontend.hostname);
record.getAddress().add(address);
Tag parentTag = Tag.buildParentTag(nginxFrontend.getKey());
record.getTags().add(parentTag);
Tag uniqueTag = UniqueTag.build(nginxService, nginxFrontend);
record.getTags().add(uniqueTag);
record.key = PlatformLayerKey.fromId(nginxFrontend.hostname);
return record;
}
use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class SiteTemplateData method resolveBackends.
private List<BackendModel> resolveBackends(List<NginxBackend> backends) throws OpsException {
List<BackendModel> resolved = Lists.newArrayList();
for (NginxBackend backend : backends) {
ItemBase backendItem = platformLayer.getItem(backend.backend);
Machine backendMachine = instances.getMachine(backendItem);
int port = 0;
if (port == 0) {
port = 80;
}
// if (address.contains(":")) {
// resolved.addAll(resolvePlatformLayer(address));
// continue;
// }
// TODO: We need to register a dependency on the resolved item
BackendModel model = new BackendModel();
model.address = backendMachine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext());
model.port = port;
resolved.add(model);
}
return resolved;
}
use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class InstanceBuilder method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
ItemBase item = ops.getInstance(ItemBase.class);
Tag parentTag = Tag.buildParentTag(item.getKey());
PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
persistentInstanceTemplate.getTags().add(parentTag);
// Set during doOperation
Machine machine = null;
PersistentInstance persistentInstance = null;
InstanceBase instance = null;
OpsTarget target = null;
persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
if (persistentInstance != null) {
// We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
// TODO: Should we always use the instance id??
instance = instances.findInstance(persistentInstance);
if (instance == null && !OpsContext.isDelete()) {
// A machine has not (yet) been assigned
throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
}
}
if (instance != null) {
machine = cloudHelpers.toMachine(instance);
}
if (addTagToManaged && !OpsContext.isDelete()) {
// Add tag with instance id to persistent instance (very helpful for
// DNS service!)
PlatformLayerKey machineKey = machine.getKey();
platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
}
SshKey sshKey = service.getSshKey();
if (machine != null) {
if (OpsContext.isDelete()) {
target = null;
machine = null;
} else {
target = machine.getTarget(sshKey);
}
}
RecursionState recursion = getRecursionState();
if (OpsContext.isDelete() && machine == null) {
// Don't recurse into no machine :-)
recursion.setPreventRecursion(true);
}
recursion.pushChildScope(Machine.class, machine);
recursion.pushChildScope(PersistentInstance.class, persistentInstance);
recursion.pushChildScope(InstanceBase.class, instance);
recursion.pushChildScope(OpsTarget.class, target);
}
Aggregations