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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations