Search in sources :

Example 66 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class FabricManager method containersForVersion.

@Override
public List<Map<String, Object>> containersForVersion(String versionId, List<String> fields) {
    Version version = profileService.getVersion(versionId);
    List<Map<String, Object>> answer = new ArrayList<Map<String, Object>>();
    if (version != null) {
        for (Container c : fabricService.getContainers()) {
            if (c.getVersion().equals(version)) {
                answer.add(BeanUtils.convertContainerToMap(fabricService, c, fields));
            }
        }
    }
    return answer;
}
Also used : Container(io.fabric8.api.Container) GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 67 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class FabricManager method addProfilesToContainer.

@Override
public void addProfilesToContainer(String container, List<String> profiles) {
    Container cont = fabricService.getContainer(container);
    cont.addProfiles(stringsToProfiles(cont.getVersion(), profiles));
}
Also used : Container(io.fabric8.api.Container)

Example 68 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class FabricManager method createContainers.

@Override
public Map<String, String> createContainers(Map<String, Object> options) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating containers from JSON data: " + options);
    }
    String providerType = (String) options.get("providerType");
    if (providerType == null) {
        throw new RuntimeException("No providerType provided");
    }
    CreateContainerBasicOptions.Builder builder = null;
    ContainerProvider provider = fabricService.getValidProviders().get(providerType);
    if (provider == null) {
        throw new RuntimeException("Can't find valid provider of type: " + providerType);
    }
    Class<?> clazz = provider.getOptionsType();
    try {
        builder = (CreateContainerBasicOptions.Builder) clazz.getMethod("builder").invoke(null);
    } catch (Exception e) {
        LOG.warn("Failed to find builder type", e);
    }
    if (builder == null) {
        throw new RuntimeException("Unknown provider type : " + providerType);
    }
    ObjectMapper mapper = getObjectMapper();
    builder = mapper.convertValue(options, builder.getClass());
    builder.zookeeperPassword(fabricService.getZookeeperPassword());
    builder.zookeeperUrl(fabricService.getZookeeperUrl());
    Object profileObject = options.get("profiles");
    if (profileObject != null) {
        List profiles = mapper.convertValue(profileObject, List.class);
        builder.profiles(profiles);
    }
    if (builder.getProxyUri() == null) {
        builder.proxyUri(fabricService.getMavenRepoURI());
    }
    CreateContainerOptions build = builder.build();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created container options: " + build + " with profiles " + build.getProfiles());
    }
    CreateContainerMetadata<?>[] metadatas = fabricService.createContainers(build);
    Map<String, String> rc = new LinkedHashMap<String, String>();
    for (CreateContainerMetadata<?> metadata : metadatas) {
        if (!metadata.isSuccess()) {
            LOG.error("Failed to create container {}: ", metadata.getContainerName(), metadata.getFailure());
            rc.put(metadata.getContainerName(), metadata.getFailure().getMessage());
        }
    }
    return rc;
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) MalformedObjectNameException(javax.management.MalformedObjectNameException) FabricException(io.fabric8.api.FabricException) MalformedURLException(java.net.MalformedURLException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ArrayList(java.util.ArrayList) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 69 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class FabricManager method containersForProfile.

@Override
public List<Map<String, Object>> containersForProfile(String versionId, String profileId, List<String> fields, boolean checkParents) {
    Version version = profileService.getVersion(versionId);
    Profile profile = version != null ? version.getRequiredProfile(profileId) : null;
    Set<Map<String, Object>> answer = new LinkedHashSet<Map<String, Object>>();
    if (profile != null) {
        for (Container c : fabricService.getContainers()) {
            for (Profile p : c.getProfiles()) {
                if (p.equals(profile)) {
                    answer.add(BeanUtils.convertContainerToMap(fabricService, c, fields));
                } else if (checkParents) {
                    HashSet<Profile> profileIDs = new HashSet<>();
                    getAllParentProfiles(version, p, profileIDs);
                    for (Profile pprofile : profileIDs) {
                        if (pprofile.equals(profile)) {
                            answer.add(BeanUtils.convertContainerToMap(fabricService, c, fields));
                            break;
                        }
                    }
                }
            }
        }
    }
    return new ArrayList<>(answer);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Container(io.fabric8.api.Container) GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Profile(io.fabric8.api.Profile) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 70 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class FabricManager method currentContainerConfigurationFiles.

/**
 * Returns a map of all the current configuration files in the profiles of
 * the current container with the file name as the key and the profile ID as
 * the value
 */
@Override
public Map<String, String> currentContainerConfigurationFiles() {
    String containerName = getCurrentContainerName();
    FabricServiceImpl service = fabricService;
    Container container = service.getContainer(containerName);
    if (container != null) {
        Profile[] profiles = container.getProfiles();
        return Profiles.getConfigurationFileNameMap(profiles);
    }
    return new HashMap<String, String>();
}
Also used : Container(io.fabric8.api.Container) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) Profile(io.fabric8.api.Profile)

Aggregations

Container (io.fabric8.api.Container)139 Test (org.junit.Test)75 FabricService (io.fabric8.api.FabricService)56 ArrayList (java.util.ArrayList)39 Container (io.fabric8.kubernetes.api.model.Container)38 IOException (java.io.IOException)38 Profile (io.fabric8.api.Profile)37 HashMap (java.util.HashMap)34 Map (java.util.Map)30 FabricException (io.fabric8.api.FabricException)27 BundleContext (org.osgi.framework.BundleContext)24 Version (io.fabric8.api.Version)23 File (java.io.File)23 HashSet (java.util.HashSet)20 LinkedList (java.util.LinkedList)17 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)16 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)16 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)15 Pod (io.fabric8.kubernetes.api.model.Pod)12 List (java.util.List)12