use of org.platformlayer.service.cloud.direct.ops.cloud.DirectCloudHost in project platformlayer by platformlayer.
the class CloudInstanceMapper method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
Tag tag = Tag.build(Tag.ASSIGNED, instance.getKey().getUrl());
List<DirectHost> hosts = Lists.newArrayList(platformLayer.listItems(DirectHost.class, TagFilter.byTag(tag)));
if (hosts.size() > 1) {
// Huh?
throw new OpsException("Multiple hosts already assigned");
}
DirectHost host;
if (hosts.isEmpty()) {
if (OpsContext.isDelete()) {
host = null;
} else {
if (createInstance) {
DirectCloudHost cloudHost = cloudMap.pickHost(instance);
host = cloudHost.getModel();
platformLayer.addTag(host.getKey(), tag);
} else {
throw new OpsException("Instance not yet assigned");
}
}
} else {
host = hosts.get(0);
}
RecursionState recursion = getRecursionState();
if (host != null) {
this.cloud = platformLayer.getItem(host.cloud, DirectCloud.class);
this.hostTarget = directHelpers.toTarget(host);
recursion.pushChildScope(cloud);
recursion.pushChildScope(host);
recursion.pushChildScope(hostTarget);
} else {
if (!OpsContext.isDelete()) {
throw new IllegalStateException();
}
log.info("No host set; won't recurse in");
recursion.setPreventRecursion(true);
}
}
Aggregations