use of org.platformlayer.images.model.DiskImageRecipe in project platformlayer by platformlayer.
the class DiskImageRecipeBuilder method loadDiskImageResource.
public static Provider<DiskImageRecipe> loadDiskImageResource(final Class<?> context, final String resourceName) {
return new ThrowingProvider<DiskImageRecipe>() {
@Override
public DiskImageRecipe build() throws OpsException {
DiskImageRecipe recipe;
try {
String recipeXml = ResourceUtils.get(context, resourceName);
recipe = JaxbHelper.deserializeXmlObject(recipeXml, DiskImageRecipe.class);
} catch (IOException e) {
throw new OpsException("Error loading recipe", e);
} catch (UnmarshalException e) {
throw new OpsException("Error loading recipe", e);
}
return recipe;
}
};
}
use of org.platformlayer.images.model.DiskImageRecipe in project platformlayer by platformlayer.
the class DiskImageRecipeBuilder method removeDetails.
protected void removeDetails() {
DiskImageRecipe recipe = getRecipe();
final Set<String> whitelistPackages = Sets.newHashSet();
final Set<String> whitelistRepos = Sets.newHashSet();
final Set<String> whitelistRepositoryKeys = Sets.newHashSet();
// whitelistPackages.add("openjdk-7-jre");
Iterables.removeIf(recipe.getAddPackage(), new Predicate<String>() {
@Override
public boolean apply(String input) {
return !whitelistPackages.contains(input);
}
});
Iterables.removeIf(recipe.getRepositoryKey(), new Predicate<RepositoryKey>() {
@Override
public boolean apply(RepositoryKey input) {
return !whitelistRepositoryKeys.contains(input.getUrl());
}
});
Iterables.removeIf(recipe.getRepository(), new Predicate<Repository>() {
@Override
public boolean apply(Repository input) {
return !whitelistRepos.contains(input.getKey());
}
});
Iterables.removeIf(recipe.getConfigurePackage(), new Predicate<ConfigurePackage>() {
@Override
public boolean apply(ConfigurePackage input) {
return !whitelistPackages.contains(input.getPackageName());
}
});
}
use of org.platformlayer.images.model.DiskImageRecipe in project platformlayer by platformlayer.
the class DiskImageRecipeBuilder method normalize.
protected void normalize() {
DiskImageRecipe recipe = getRecipe();
List<String> packages = recipe.getAddPackage();
Collections.sort(packages);
String previous = null;
Iterator<String> it = packages.iterator();
while (it.hasNext()) {
String packageName = it.next();
if (Objects.equal(previous, packageName)) {
it.remove();
}
previous = packageName;
}
// TODO: Other collections!
}
use of org.platformlayer.images.model.DiskImageRecipe in project platformlayer by platformlayer.
the class ImageFactory method isMatch.
private boolean isMatch(DiskImageRecipe a, DiskImageRecipe b) {
// TODO: Don't be evil
DiskImageRecipe aCopy = cloneThroughJaxb(a);
DiskImageRecipe 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);
}
}
use of org.platformlayer.images.model.DiskImageRecipe in project platformlayer by platformlayer.
the class ImageFactory method getOrCreateImageId.
public CloudImage getOrCreateImageId(MachineProvider targetCloud, List<ImageFormat> formats, DiskImageRecipe recipeTemplate) throws OpsException {
DiskImageRecipe recipeItem = getOrCreateRecipe(recipeTemplate);
PlatformLayerKey recipeKey = recipeItem.getKey();
return getOrCreateImageId(targetCloud, formats, recipeKey);
}
Aggregations