Search in sources :

Example 1 with DiskImageRecipe

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;
        }
    };
}
Also used : OpsException(org.platformlayer.ops.OpsException) DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe) UnmarshalException(javax.xml.bind.UnmarshalException) IOException(java.io.IOException)

Example 2 with DiskImageRecipe

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());
        }
    });
}
Also used : ConfigurePackage(org.platformlayer.images.model.ConfigurePackage) Repository(org.platformlayer.images.model.Repository) DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe) RepositoryKey(org.platformlayer.images.model.RepositoryKey)

Example 3 with DiskImageRecipe

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!
}
Also used : DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe)

Example 4 with DiskImageRecipe

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);
    }
}
Also used : DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe) OpsException(org.platformlayer.ops.OpsException) PlatformLayerClientException(org.platformlayer.PlatformLayerClientException)

Example 5 with DiskImageRecipe

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);
}
Also used : DiskImageRecipe(org.platformlayer.images.model.DiskImageRecipe) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey)

Aggregations

DiskImageRecipe (org.platformlayer.images.model.DiskImageRecipe)10 OpsException (org.platformlayer.ops.OpsException)5 IOException (java.io.IOException)2 Tag (org.platformlayer.core.model.Tag)2 OperatingSystemRecipe (org.platformlayer.images.model.OperatingSystemRecipe)2 SshKey (org.platformlayer.ops.helpers.SshKey)2 CloudImage (org.platformlayer.ops.images.CloudImage)2 ImageFormat (org.platformlayer.ops.images.ImageFormat)2 MachineProvider (org.platformlayer.ops.machines.MachineProvider)2 AccessConfig (com.google.api.services.compute.model.AccessConfig)1 Image (com.google.api.services.compute.model.Image)1 Instance (com.google.api.services.compute.model.Instance)1 MachineType (com.google.api.services.compute.model.MachineType)1 Metadata (com.google.api.services.compute.model.Metadata)1 Items (com.google.api.services.compute.model.Metadata.Items)1 NetworkInterface (com.google.api.services.compute.model.NetworkInterface)1 Operation (com.google.api.services.compute.model.Operation)1 File (java.io.File)1 List (java.util.List)1 Set (java.util.Set)1