Search in sources :

Example 51 with ItemBase

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) Tag(org.platformlayer.core.model.Tag) TagChanges(org.platformlayer.core.model.TagChanges)

Example 52 with ItemBase

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;
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) DatabaseServer(org.platformlayer.ops.databases.DatabaseServer)

Example 53 with ItemBase

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);
    }
}
Also used : HasPorts(org.platformlayer.ops.networks.HasPorts) ItemBase(org.platformlayer.core.model.ItemBase) NetworkConnection(org.platformlayer.service.network.model.NetworkConnection) Protocol(org.platformlayer.ops.firewall.Protocol) Transport(org.platformlayer.ops.firewall.Transport) UUID(java.util.UUID)

Example 54 with ItemBase

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);
    }
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) OpsContext(org.platformlayer.ops.OpsContext) Machine(org.platformlayer.ops.Machine) BindingScope(org.platformlayer.ops.BindingScope)

Example 55 with ItemBase

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);
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) InetAddressChooser(org.platformlayer.InetAddressChooser) DatabaseServer(org.platformlayer.ops.databases.DatabaseServer)

Aggregations

ItemBase (org.platformlayer.core.model.ItemBase)56 OpsException (org.platformlayer.ops.OpsException)20 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)14 RepositoryException (org.platformlayer.RepositoryException)11 OpsContext (org.platformlayer.ops.OpsContext)11 Tag (org.platformlayer.core.model.Tag)8 BindingScope (org.platformlayer.ops.BindingScope)7 Machine (org.platformlayer.ops.Machine)7 DatabaseServer (org.platformlayer.ops.databases.DatabaseServer)6 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)6 Produces (javax.ws.rs.Produces)5 List (java.util.List)4 GET (javax.ws.rs.GET)4 TagChanges (org.platformlayer.core.model.TagChanges)4 OpsTarget (org.platformlayer.ops.OpsTarget)4 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)4 JAXBException (javax.xml.bind.JAXBException)3 Filter (org.platformlayer.Filter)3 InetAddressChooser (org.platformlayer.InetAddressChooser)3 StateFilter (org.platformlayer.StateFilter)3