Search in sources :

Example 26 with ItemBase

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

Example 27 with ItemBase

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

Example 28 with ItemBase

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

Example 29 with ItemBase

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;
}
Also used : NginxBackend(org.openstack.service.nginx.model.NginxBackend) ItemBase(org.platformlayer.core.model.ItemBase) Machine(org.platformlayer.ops.Machine) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 30 with ItemBase

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;
}
Also used : UntypedItem(org.platformlayer.common.UntypedItem) ItemBase(org.platformlayer.core.model.ItemBase)

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