Search in sources :

Example 61 with Container

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

the class BeanUtils method getFields.

public static List<String> getFields(Class clazz) {
    List<String> answer = new ArrayList<String>();
    try {
        for (PropertyDescriptor desc : PropertyUtils.getPropertyDescriptors(clazz)) {
            if (desc.getReadMethod() != null) {
                answer.add(desc.getName());
            }
        }
    } catch (Exception e) {
        throw new FabricException("Failed to get property descriptors for " + clazz.toString(), e);
    }
    // few tweaks to maintain compatibility with existing views for now...
    if (clazz.getSimpleName().equals("Container")) {
        answer.add("parentId");
        answer.add("versionId");
        answer.add("profileIds");
        answer.add("childrenIds");
        answer.remove("fabricService");
    } else if (clazz.getSimpleName().equals("Profile")) {
        answer.add("id");
        answer.add("parentIds");
        answer.add("childIds");
        answer.add("containerCount");
        answer.add("containers");
        answer.add("fileConfigurations");
    } else if (clazz.getSimpleName().equals("Version")) {
        answer.add("id");
        answer.add("defaultVersion");
    }
    return answer;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException)

Example 62 with Container

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

the class FabricManager method applyVersionToContainers.

@Override
public void applyVersionToContainers(String targetVersion, List<String> containerIds) {
    Version version = profileService.getVersion(targetVersion);
    for (String containerId : containerIds) {
        Container container = fabricService.getContainer(containerId);
        List<Profile> profiles = Arrays.asList(container.getProfiles());
        for (Profile profile : profiles) {
            if (!profileService.hasProfile(version.getId(), profile.getId())) {
                String noVersionForProfile = String.format("Can't upgrade container %s since profile %s does not have version %s", containerId, profile.getId(), version.getId());
                throw new IllegalStateException(noVersionForProfile);
            }
        }
        container.setVersion(version);
    }
}
Also used : Container(io.fabric8.api.Container) GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 63 with Container

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

the class FabricManager method deleteVersion.

@Override
public void deleteVersion(String versionId) {
    Container[] containers = fabricService.getContainers();
    StringBuilder sb = new StringBuilder();
    for (Container container : fabricService.getContainers()) {
        if (versionId.equals(container.getVersionId())) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(container.getId());
        }
    }
    IllegalStateAssertion.assertTrue(sb.length() == 0, "Version " + versionId + " is still used by the following containers: " + sb.toString());
    profileService.deleteVersion(versionId);
}
Also used : Container(io.fabric8.api.Container)

Example 64 with Container

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

the class FabricManager method getJvmOpts.

@Override
public /**
 * Returns configured jvmOpts only for (local and remote) Karaf containers.
 */
String getJvmOpts(String containerName) {
    String result = "";
    Container container = fabricService.getContainer(containerName);
    CreateContainerBasicMetadata metadata = (CreateContainerBasicMetadata) container.getMetadata();
    if (metadata == null) {
        return "Inapplicable";
    }
    switch(metadata.getCreateOptions().getProviderType()) {
        case "child":
        case "ssh":
            CreateContainerOptions createOptions = metadata.getCreateOptions();
            result = createOptions.getJvmOpts();
            break;
        default:
            result = "Inapplicable";
    }
    return result;
}
Also used : Container(io.fabric8.api.Container) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) CreateContainerBasicMetadata(io.fabric8.api.CreateContainerBasicMetadata)

Example 65 with Container

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

the class FabricManager method containers.

@Override
public List<Map<String, Object>> containers(List<String> fields, List<String> profileFields) {
    List<Map<String, Object>> answer = new ArrayList<Map<String, Object>>();
    for (Container c : fabricService.getContainers()) {
        Map<String, Object> map = BeanUtils.convertContainerToMap(fabricService, c, fields);
        List<Map<String, Object>> profiles = new ArrayList<Map<String, Object>>();
        for (Profile p : c.getProfiles()) {
            profiles.add(BeanUtils.convertProfileToMap(fabricService, p, profileFields));
        }
        map.put("profiles", profiles);
        answer.add(map);
    }
    return answer;
}
Also used : Container(io.fabric8.api.Container) 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)

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