Search in sources :

Example 1 with InstanceBase

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

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

the class PlatformLayerCloudHelpers method buildInstanceTemplate.

InstanceBase buildInstanceTemplate(MachineCreationRequest request, PlatformLayerKey parent) throws OpsException {
    MachineProvider targetCloud = scheduler.pickCloud(request);
    InstanceBase machine = targetCloud.buildInstanceTemplate(request);
    machine.sshPublicKey = SshKeys.serialize(request.sshPublicKey);
    machine.recipeId = request.recipeId;
    if (request.publicPorts != null) {
        if (machine.publicPorts == null) {
            machine.publicPorts = Lists.newArrayList();
        }
        machine.publicPorts.addAll(request.publicPorts);
    }
    machine.getTags().addAll(request.tags);
    if (parent != null) {
        machine.getTags().add(Tag.buildParentTag(parent));
    }
    machine.cloud = targetCloud.getModel().getKey();
    machine.hostPolicy = request.hostPolicy;
    String id = request.hostname;
    if (Strings.isNullOrEmpty(id)) {
        id = UUID.randomUUID().toString();
    }
    machine.setKey(PlatformLayerKey.fromId(id));
    return machine;
}
Also used : InstanceBase(org.platformlayer.core.model.InstanceBase)

Example 3 with InstanceBase

use of org.platformlayer.core.model.InstanceBase 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 4 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 5 with InstanceBase

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

the class InstanceFinder method foundItem.

@Override
protected void foundItem(ItemBase child) throws OpsException {
    super.foundItem(child);
    if (child instanceof InstanceBase) {
        instances.add((InstanceBase) child);
    }
    PlatformLayerKey assignedTo = Tag.ASSIGNED_TO.findUnique(child.getTags());
    if (assignedTo != null) {
        scheduleVisit(assignedTo);
    }
}
Also used : PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) 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