use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class PlatformlayerBackedPool method assign.
@Override
public T assign(PlatformLayerKey owner, boolean required) throws OpsException {
T assigned = findAssigned(owner);
if (assigned != null) {
return assigned;
}
for (int i = 0; i < 10; i++) {
ItemBase resource = platformLayer.getItem(resourceKey);
String assignedItem = pickUnassigned(resource);
if (assignedItem == null) {
break;
}
Assignment assignment = new Assignment(owner.getUrl(), assignedItem, subkey);
Tag assignmentTag = assignment.asTag();
TagChanges tagChanges = new TagChanges();
tagChanges.addTags.add(assignmentTag);
if (null != platformLayer.changeTags(resourceKey, tagChanges, resource.getVersion())) {
return adapter.toItem(assignedItem);
}
if (!TimeSpan.ONE_SECOND.doSafeSleep()) {
break;
}
}
if (required) {
throw new OpsException("Unable to assign value from pool: " + toString());
}
return null;
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class GerritDatabaseTemplate method getAuthJdbcUrl.
protected String getAuthJdbcUrl() throws OpsException {
PlatformLayerKey serverKey = getModel().server;
ItemBase serverItem = (ItemBase) platformLayer.getItem(serverKey);
DatabaseServer server = databases.toDatabase(serverItem);
String jdbc = server.getJdbcUrl(getDatabaseName(), InetAddressChooser.preferIpv6());
return jdbc;
}
use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.
the class NetworkConnectionController method addChildren.
@Override
protected void addChildren() throws OpsException {
NetworkConnection model = ops.getInstance(NetworkConnection.class);
Protocol protocol = null;
if (model.protocol != null) {
protocol = EnumUtils.valueOfCaseInsensitive(Protocol.class, model.protocol);
}
Transport transport = null;
// if (model.transport != null) {
// protocol = EnumUtils.valueOfCaseInsensitive(Transport.class, model.transport);
// }
List<Integer> ports = Lists.newArrayList();
if (model.port != 0) {
ports.add(model.port);
if (model.protocol == null) {
protocol = Protocol.Tcp;
}
} else {
ItemBase destItem = platformLayer.getItem(model.destItem);
HasPorts hasPorts = providers.toInterface(destItem, HasPorts.class);
ports.addAll(hasPorts.getPorts());
if (model.protocol == null) {
// TODO: Support UDP?
protocol = Protocol.Tcp;
}
}
UUID uniqueId = platformLayer.getOrCreateUuid(model);
for (int port : ports) {
PlatformLayerFirewallEntry net = injected(PlatformLayerFirewallEntry.class);
net.destItem = model.destItem;
net.port = port;
net.sourceItemKey = model.sourceItem;
net.sourceCidr = model.sourceCidr;
net.protocol = protocol;
net.transport = transport;
net.uniqueId = port + "-" + uniqueId.toString();
addChild(net);
}
}
use of org.platformlayer.core.model.ItemBase 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.core.model.ItemBase in project platformlayer by platformlayer.
the class PlatformLayerAuthDatabaseController 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);
}
Aggregations