use of org.platformlayer.images.model.DiskImage in project platformlayer by platformlayer.
the class ImageFactory method getOrCreateImageId.
public CloudImage getOrCreateImageId(MachineProvider targetCloud, List<ImageFormat> formats, PlatformLayerKey recipeKey) throws OpsException {
if (recipeKey == null) {
log.debug("Looking for bootstrap image");
for (ImageFormat format : formats) {
CloudImage bootstrapImage = findBootstrapImage(format, cloud.getImageStore(targetCloud));
if (bootstrapImage != null) {
return bootstrapImage;
// Tags tags = bootstrapImage.getTags();
// String compression = tags.findUnique("org.openstack.sync__1__expand");
// return new ImageInfo(bootstrapImage.getId(), format, compression);
}
}
throw new OpsException("Cannot find bootstrap image for format " + Joiner.on(",").join(formats));
}
DiskImage imageTemplate = new DiskImage();
imageTemplate.setFormat(formats.get(0).name());
imageTemplate.setRecipeId(recipeKey);
String id = "image-" + recipeKey.getItemId().getKey();
imageTemplate.setKey(PlatformLayerKey.fromId(id));
PlatformLayerKey cloudKey = targetCloud.getModel().getKey();
imageTemplate.setCloud(cloudKey);
DiskImage image = getOrCreateImage(imageTemplate);
return getImageInfo(image);
}
use of org.platformlayer.images.model.DiskImage in project platformlayer by platformlayer.
the class ImageFactory method getOrCreateImage.
public DiskImage getOrCreateImage(DiskImage template) throws OpsException {
DiskImage best = null;
try {
for (DiskImage candidate : platformLayer.listItems(DiskImage.class)) {
if (isMatch(candidate, template)) {
best = candidate;
break;
}
}
if (best == null) {
// We should be owned by the recipe
PlatformLayerKey recipeKey = template.getRecipeId();
if (recipeKey != null) {
template.getTags().add(Tag.buildParentTag(recipeKey));
}
best = platformLayer.putItem(template);
}
} catch (PlatformLayerClientException e) {
throw new OpsException("Error fetching or building image", e);
}
return best;
}
use of org.platformlayer.images.model.DiskImage in project platformlayer by platformlayer.
the class ImageFactory method isMatch.
private boolean isMatch(DiskImage a, DiskImage b) {
// TODO: Don't be evil
DiskImage aCopy = cloneThroughJaxb(a);
DiskImage bCopy = cloneThroughJaxb(b);
aCopy.setKey(null);
bCopy.setKey(null);
aCopy.tags = null;
bCopy.tags = null;
aCopy.version = 0;
bCopy.version = 0;
aCopy.state = null;
bCopy.state = null;
aCopy.secret = null;
bCopy.secret = null;
try {
// TODO: What if e.g. package order is different
String aXml = JaxbHelper.toXml(aCopy, false);
String bXml = JaxbHelper.toXml(bCopy, false);
return Objects.equal(aXml, bXml);
} catch (Exception e) {
throw new IllegalArgumentException("Error comparing objects", e);
}
}
Aggregations