use of org.platformlayer.core.model.ItemBase 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.core.model.ItemBase in project platformlayer by platformlayer.
the class PlatformLayerCloudHelpers method findMachines.
public List<InstanceBase> findMachines(Tag tag) throws OpsException {
if (!Objects.equal(tag.getKey(), Tag.PARENT.getKey())) {
throw new IllegalArgumentException();
}
List<InstanceBase> machines = Lists.newArrayList();
boolean showDeleted = false;
PlatformLayerKey parent = PlatformLayerKey.parse(tag.getValue());
for (ItemBase item : platformLayer.listChildrenTyped(parent, showDeleted)) {
if (item instanceof InstanceBase) {
machines.add((InstanceBase) item);
}
}
return machines;
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class PlatformLayerDatabaseController method buildLinkTargetConfiguration.
@Override
public Map<String, String> buildLinkTargetConfiguration(LinkConsumer consumer) throws OpsException {
ItemBase serverItem = platformLayer.getItem(model.server);
DatabaseServer databaseServer = providers.toInterface(serverItem, DatabaseServer.class);
InetAddressChooser inetAddressChooser = consumer.getInetAddressChooser();
return databaseServer.buildTargetConfiguration(model.username, model.password, model.databaseName, inetAddressChooser);
}
use of org.platformlayer.core.model.ItemBase 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.core.model.ItemBase in project platformlayer by platformlayer.
the class PlatformLayerClientBase method listChildrenTyped.
@Override
public List<ItemBase> listChildrenTyped(PlatformLayerKey parent, boolean includeDeleted) throws OpsException {
List<ItemBase> ret = Lists.newArrayList();
for (UntypedItem item : listChildren(parent, includeDeleted).getItems()) {
ItemBase typedItem = promoteToTyped(item);
ret.add(typedItem);
}
return ret;
}
Aggregations