Search in sources :

Example 41 with ItemBase

use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.

the class PlatformLayerTestContext method cleanup.

public void cleanup() throws IOException, OpsException {
    while (!ownedItems.isEmpty()) {
        ItemBase item = ownedItems.remove(ownedItems.size() - 1);
        JobData deleteJob = deleteItem(item);
        System.out.println("Deleted " + item.getKey() + " jobId=" + deleteJob.getJobId());
        waitForDeleted(item);
    }
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) JobData(org.platformlayer.jobs.model.JobData)

Example 42 with ItemBase

use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.

the class LinkHelpers method buildLinkTargetProperties.

// public InetAddressChooser inetAddressChooser = InetAddressChooser.preferIpv6();
public Map<String, String> buildLinkTargetProperties(LinkConsumer consumer, List<Link> links) throws OpsException {
    Map<String, String> config = Maps.newHashMap();
    if (links != null) {
        for (Link link : links) {
            ItemBase item = platformLayer.getItem(link.getTarget());
            LinkTarget linkTarget = providers.toInterface(item, LinkTarget.class);
            Map<String, String> linkTargetConfig = buildLinkTargetConfiguration(consumer, link.name, linkTarget);
            config.putAll(linkTargetConfig);
        }
    }
    return config;
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) Link(org.platformlayer.core.model.Link)

Example 43 with ItemBase

use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.

the class IpsecInstall method addChildren.

@Override
protected void addChildren() throws OpsException {
    addChild(PackageDependency.build("racoon"));
    addChild(SimpleFile.build(getClass(), new File("/etc/racoon/racoon.conf")));
    // addChild(SimpleFile.build(getClass(), new File("/etc/racoon/psk.txt")));
    addChild(SimpleFile.build(getClass(), new File("/etc/ipsec-tools.conf")));
    addChild(IpsecBootstrap.class);
    ItemBase model = OpsContext.get().getInstance(ItemBase.class);
    String uuid = platformLayerClient.getOrCreateUuid(model).toString();
    // TODO: Rationalize between our complicated version that can open cloud ports, and this streamlined version
    for (Transport transport : Transport.all()) {
        {
            IptablesFilterEntry allowIKE = addChild(IptablesFilterEntry.class);
            allowIKE.port = 500;
            allowIKE.protocol = Protocol.Udp;
            allowIKE.ruleKey = transport.getKey() + "-ike-" + uuid;
            allowIKE.transport = transport;
        }
        {
            // TODO: Do we want to open NAT-T (4500?)
            IptablesFilterEntry allowEsp = addChild(IptablesFilterEntry.class);
            allowEsp.protocol = Protocol.Esp;
            allowEsp.ruleKey = transport.getKey() + "-esp-" + uuid;
            allowEsp.transport = transport;
        }
        // AH iptables allow doesn't seem to work
        // AllowProtocol allowAh = addChild(AllowProtocol.class);
        // allowAh.protocol = Protocol.Ah;
        // allowAh.uuid = "ah-" + uuid;
        {
            IptablesFilterPolicy allowPolicy = addChild(IptablesFilterPolicy.class);
            allowPolicy.direction = Direction.In;
            allowPolicy.policy = "ipsec";
            allowPolicy.ruleKey = transport.getKey() + "-ipsec-" + uuid;
            allowPolicy.transport = transport;
        }
    }
    addChild(ManagedService.build("racoon"));
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) Transport(org.platformlayer.ops.firewall.Transport) IptablesFilterEntry(org.platformlayer.ops.firewall.scripts.IptablesFilterEntry) IptablesFilterPolicy(org.platformlayer.ops.firewall.scripts.IptablesFilterPolicy) File(java.io.File) SimpleFile(org.platformlayer.ops.filesystem.SimpleFile)

Example 44 with ItemBase

use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.

the class ForEach method processDataItems.

private boolean processDataItems(Object controller, List<ItemBase> dataItems, ItemBase machineItem, Machine machine, OpsTarget target) {
    boolean failed = false;
    for (ItemBase dataItem : dataItems) {
        try {
            // Execute the children in a scope
            BindingScope scope = BindingScope.push(machine, target, machineItem, dataItem);
            try {
                OpsContext opsContext = OpsContext.get();
                OperationRecursor.doRecurseChildren(opsContext, controller);
            } finally {
                scope.pop();
            }
        } catch (OpsException e) {
            failed = true;
            log.warn("Error updating machine: " + machine + " with item " + dataItem, e);
        }
    }
    return failed;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Example 45 with ItemBase

use of org.platformlayer.core.model.ItemBase in project platformlayer by platformlayer.

the class TagFromChildren method handler.

@Handler
public void handler() throws OpsException {
    if (OpsContext.isConfigure()) {
        for (OwnedItem<?> childServer : parentController.getChildren(OwnedItem.class)) {
            ItemBase server = childServer.getItem();
            if (server == null) {
                // Right now, we have to go through a retry cycle
                throw new OpsException("Child server not ready");
            }
            List<EndpointInfo> endpoints = EndpointInfo.findEndpoints(server.getTags(), port);
            if (endpoints.isEmpty()) {
                // TODO: Cope in future e.g. if we only need one of two in a cluster
                throw new OpsException("Child server not ready");
            }
            for (EndpointInfo endpoint : endpoints) {
                platformLayer.addTag(parentItem.getKey(), endpoint.toTag());
            }
        }
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) Handler(org.platformlayer.ops.Handler)

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