Search in sources :

Example 6 with InstanceBase

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

the class PlatformLayerCloudHelpers method putInstanceByTag.

public Machine putInstanceByTag(MachineCreationRequest request, PlatformLayerKey parent, Tag uniqueTag) throws OpsException {
    InstanceBase machine = buildInstanceTemplate(request, parent);
    machine = platformLayer.putItemByTag(machine, uniqueTag);
    return toMachine(machine);
}
Also used : InstanceBase(org.platformlayer.core.model.InstanceBase)

Example 7 with InstanceBase

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

the class InstanceBuilder method doOperation.

@Handler
public void doOperation() throws OpsException, IOException {
    ItemBase item = ops.getInstance(ItemBase.class);
    Tag parentTag = Tag.buildParentTag(item.getKey());
    PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();
    persistentInstanceTemplate.getTags().add(parentTag);
    // Set during doOperation
    Machine machine = null;
    PersistentInstance persistentInstance = null;
    InstanceBase instance = null;
    OpsTarget target = null;
    persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);
    if (persistentInstance != null) {
        // We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
        // TODO: Should we always use the instance id??
        instance = instances.findInstance(persistentInstance);
        if (instance == null && !OpsContext.isDelete()) {
            // A machine has not (yet) been assigned
            throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
        }
    }
    if (instance != null) {
        machine = cloudHelpers.toMachine(instance);
    }
    if (addTagToManaged && !OpsContext.isDelete()) {
        // Add tag with instance id to persistent instance (very helpful for
        // DNS service!)
        PlatformLayerKey machineKey = machine.getKey();
        platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
    }
    SshKey sshKey = service.getSshKey();
    if (machine != null) {
        if (OpsContext.isDelete()) {
            target = null;
            machine = null;
        } else {
            target = machine.getTarget(sshKey);
        }
    }
    RecursionState recursion = getRecursionState();
    if (OpsContext.isDelete() && machine == null) {
        // Don't recurse into no machine :-)
        recursion.setPreventRecursion(true);
    }
    recursion.pushChildScope(Machine.class, machine);
    recursion.pushChildScope(PersistentInstance.class, persistentInstance);
    recursion.pushChildScope(InstanceBase.class, instance);
    recursion.pushChildScope(OpsTarget.class, target);
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) PersistentInstance(org.platformlayer.instances.model.PersistentInstance) ItemBase(org.platformlayer.core.model.ItemBase) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) Tag(org.platformlayer.core.model.Tag) InstanceBase(org.platformlayer.core.model.InstanceBase) Machine(org.platformlayer.ops.Machine) Handler(org.platformlayer.ops.Handler)

Example 8 with InstanceBase

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

the class PlatformLayerCloudContext method refreshMachine.

@Override
public Machine refreshMachine(Machine machine) throws OpsException {
    PlatformLayerKey key = machine.getKey();
    InstanceBase refreshed = findInstanceByInstanceKey(key);
    return cloudHelpers.toMachine(refreshed);
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) InstanceBase(org.platformlayer.core.model.InstanceBase)

Example 9 with InstanceBase

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

the class PlatformLayerCloudHelpers method getStorageConfiguration.

public StorageConfiguration getStorageConfiguration(Machine machine) throws OpsException {
    InstanceBase instance = toInstance(machine);
    PlatformLayerKey cloudKey = instance.cloud;
    MachineProvider cloud = getCloud(cloudKey);
    return getStorageConfiguration(cloud);
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) InstanceBase(org.platformlayer.core.model.InstanceBase)

Example 10 with InstanceBase

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

the class PlatformLayerCloudHelpers method terminateMachine.

public void terminateMachine(Machine machine) throws OpsException {
    if (machine == null) {
        throw new IllegalArgumentException();
    }
    InstanceBase instance = toInstance(machine);
    if (instance == null) {
        throw new IllegalStateException();
    }
    platformLayer.deleteItem(instance.getKey());
}
Also used : InstanceBase(org.platformlayer.core.model.InstanceBase)

Aggregations

InstanceBase (org.platformlayer.core.model.InstanceBase)10 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)6 ItemBase (org.platformlayer.core.model.ItemBase)2 Tag (org.platformlayer.core.model.Tag)2 PublicEndpointBase (org.platformlayer.core.model.PublicEndpointBase)1 PersistentInstance (org.platformlayer.instances.model.PersistentInstance)1 Handler (org.platformlayer.ops.Handler)1 Machine (org.platformlayer.ops.Machine)1 OpsException (org.platformlayer.ops.OpsException)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 UniqueTag (org.platformlayer.ops.UniqueTag)1 SshKey (org.platformlayer.ops.helpers.SshKey)1