use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class DirectCloudUtils method toTarget.
public OpsTarget toTarget(DirectHost host) throws OpsException {
NetworkPoint address = NetworkPoint.forPublicHostname(host.host);
Machine hostMachine = new OpaqueMachine(address);
OpsTarget hostTarget = hostMachine.getTarget(service.getSshKey());
return hostTarget;
}
use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.
the class DirectTarget method doRecurseOperation.
@Override
public void doRecurseOperation() throws OpsException {
Machine machine = new OpaqueMachine(address);
OpsTarget target = machine.getTarget(sshKey);
BindingScope scope = BindingScope.push(machine, target);
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 OpenstackBackupContextFactory method build.
@Override
public OpenstackBackupContext build(ItemBase item) throws OpsException {
Machine machine = instances.findMachine(item);
if (machine == null) {
throw new OpsException("Cannot determine machine for: " + item);
}
StorageConfiguration storageConfiguration = cloud.getStorageConfiguration(machine);
return build(storageConfiguration);
}
use of org.platformlayer.ops.Machine 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.Machine in project platformlayer by platformlayer.
the class ZookeeperInstanceModel method getCluster.
public Cluster getCluster() throws OpsException {
Cluster cluster = new Cluster();
for (ZookeeperServer server : getClusterServers()) {
// TODO: Do keys need to be sequential
ClusterServer model = new ClusterServer();
model.key = server.clusterId;
// TODO: What do we do about machines that don't yet have an ip?
NetworkPoint targetNetworkPoint = NetworkPoint.forPublicInternet();
Machine sourceMachine = instances.getMachine(server);
String address = sourceMachine.getNetworkPoint().getBestAddress(targetNetworkPoint);
model.ip = address;
model.dnsName = ZookeeperUtils.buildDnsName(server);
cluster.servers.add(model);
}
return cluster;
}
Aggregations