Search in sources :

Example 41 with PlatformLayerKey

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

the class SchedulerImpl method toRunnable.

private Runnable toRunnable(final ActionTask task) {
    final PlatformLayerKey target = task.target;
    final PlatformLayerEndpointInfo endpoint = rehydrateEndpoint(task.endpoint);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                PlatformLayerClient platformLayer = HttpPlatformLayerClient.build(httpStrategy, endpoint.getPlatformlayerBaseUrl(), endpoint.getAuthenticator(), endpoint.getProjectId(), endpoint.getTrustKeys());
                platformLayer.doAction(target, task.action);
            // TODO: Wait for task completion??
            // TODO: Link job id??
            } catch (PlatformLayerClientException e) {
                log.warn("Error running action", e);
            }
        }

        @Override
        public String toString() {
            return task.action + " on " + task.target;
        }
    };
    return runnable;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) PlatformLayerClientException(org.platformlayer.PlatformLayerClientException) PlatformLayerEndpointInfo(org.platformlayer.PlatformLayerEndpointInfo) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 42 with PlatformLayerKey

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

the class StandardTemplateData method findPublicSslKey.

public ManagedSecretKey findPublicSslKey() throws OpsException {
    PlatformLayerKey sslKey = getSslKeyPath();
    if (sslKey == null) {
        if (getCaPath() != null) {
            ManagedSecretKey key = findCaSignedKey("public");
            if (key != null) {
                return key;
            }
        }
        return null;
    }
    ItemBase sslKeyItem = (ItemBase) platformLayer.getItem(sslKey);
    ManagedSecretKey key = providers.toInterface(sslKeyItem, ManagedSecretKey.class);
    return key;
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) ManagedSecretKey(org.platformlayer.ops.crypto.ManagedSecretKey) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Example 43 with PlatformLayerKey

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

the class OwnedEndpoint method buildItemTemplate.

@Override
protected PublicEndpointBase buildItemTemplate() throws OpsException {
    InstanceBase instance = OpsContext.get().getInstance(InstanceBase.class);
    PlatformLayerKey instanceKey = instance.getKey();
    PublicEndpointBase publicEndpoint = platformLayerCloudHelpers.createPublicEndpoint(instance, parentItem);
    // publicEndpoint.network = network;
    publicEndpoint.publicPort = publicPort;
    publicEndpoint.publicPortCluster = publicPortCluster;
    publicEndpoint.backendPort = backendPort;
    publicEndpoint.instance = instanceKey;
    publicEndpoint.key = PlatformLayerKey.fromId(instance.getId() + "_" + publicPort);
    if (transport != null) {
        publicEndpoint.transport = transport.toString();
    }
    // publicEndpoint.getTags().add(OpsSystem.get().createParentTag(instance));
    Tag uniqueTag = UniqueTag.build(instance, String.valueOf(publicPort));
    publicEndpoint.getTags().add(uniqueTag);
    return publicEndpoint;
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) UniqueTag(org.platformlayer.ops.UniqueTag) Tag(org.platformlayer.core.model.Tag) PublicEndpointBase(org.platformlayer.core.model.PublicEndpointBase) InstanceBase(org.platformlayer.core.model.InstanceBase)

Example 44 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey 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 45 with PlatformLayerKey

use of org.platformlayer.core.model.PlatformLayerKey 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)

Aggregations

PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)86 PlatformLayerClient (org.platformlayer.PlatformLayerClient)21 OpsException (org.platformlayer.ops.OpsException)16 ItemBase (org.platformlayer.core.model.ItemBase)14 ManagedItemId (org.platformlayer.ids.ManagedItemId)13 UntypedItem (org.platformlayer.common.UntypedItem)10 ProjectId (org.platformlayer.ids.ProjectId)10 Tag (org.platformlayer.core.model.Tag)8 RepositoryException (org.platformlayer.RepositoryException)7 ServiceType (org.platformlayer.ids.ServiceType)7 JobData (org.platformlayer.jobs.model.JobData)7 InstanceBase (org.platformlayer.core.model.InstanceBase)6 ItemType (org.platformlayer.ids.ItemType)6 OpsTarget (org.platformlayer.ops.OpsTarget)6 JaxbHelper (org.platformlayer.xml.JaxbHelper)6 Handler (org.platformlayer.ops.Handler)5 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)4 UntypedItemXml (org.platformlayer.UntypedItemXml)4 FederationKey (org.platformlayer.ids.FederationKey)4 Machine (org.platformlayer.ops.Machine)4