Search in sources :

Example 51 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class SshAutoScalerTest method assertSshAutoScale.

public static HostProfileCounter assertSshAutoScale(FabricRequirements requirements, AutoScaleStatus status) {
    HostProfileCounter hostProfileCounter = new HostProfileCounter();
    String version = requirements.getVersion();
    if (Strings.isEmpty(version)) {
        version = "1.0";
    }
    List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
    for (ProfileRequirements profileRequirement : profileRequirements) {
        Integer minimumInstances = profileRequirement.getMinimumInstances();
        if (minimumInstances != null) {
            for (int i = 0; i < minimumInstances; i++) {
                String profileId = profileRequirement.getProfile();
                AutoScaleRequest request = new AutoScaleRequest(null, version, profileId, 1, requirements, profileRequirement, status);
                CreateSshContainerOptions.Builder builder = chooseHostContainerOptions(request, hostProfileCounter);
                assertNotNull("Should have found a builder for " + profileId, builder);
                String host = builder.getHost();
                hostProfileCounter.incrementContainers(host);
                hostProfileCounter.incrementProfileCount(host, profileId);
            }
        }
    }
    Map<String, CountingMap> hostToProfileCounts = hostProfileCounter.getHostToProfileCounts();
    assertProfilesUseSeparateHost(requirements, hostToProfileCounts);
    assertMaximumContainerCountNotExceeded(requirements, hostToProfileCounts);
    return hostProfileCounter;
}
Also used : CountingMap(io.fabric8.utils.CountingMap) ProfileRequirements(io.fabric8.api.ProfileRequirements) AutoScaleRequest(io.fabric8.api.AutoScaleRequest) HostProfileCounter(io.fabric8.internal.autoscale.HostProfileCounter)

Example 52 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class BeanUtils method convertContainerToMap.

public static Map<String, Object> convertContainerToMap(FabricService fabricService, Container container, List<String> fields) {
    Map<String, Object> answer = new TreeMap<String, Object>();
    for (String field : fields) {
        if (field.equalsIgnoreCase("profiles") || field.equalsIgnoreCase("profileIds")) {
            answer.put(field, Ids.getIds(container.getProfiles()));
        } else if (field.equalsIgnoreCase("childrenIds") || field.equalsIgnoreCase("children")) {
            answer.put(field, Ids.getIds(container.getChildren()));
        } else if (field.equalsIgnoreCase("parent") || field.equalsIgnoreCase("parentId")) {
            answer.put(field, Ids.getId(container.getParent()));
        } else if (field.equalsIgnoreCase("version") || field.equalsIgnoreCase("versionId")) {
            answer.put(field, container.getVersionId());
        } else if (field.equalsIgnoreCase("overlayProfile")) {
            Profile overlayProfile = container.getOverlayProfile();
            Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
            answer.put(field, convertProfileToMap(fabricService, effectiveProfile, getFields(Profile.class)));
        } else {
            addProperty(container, field, answer);
        }
    }
    return answer;
}
Also used : TreeMap(java.util.TreeMap) Profile(io.fabric8.api.Profile)

Example 53 with Version

use of io.fabric8.api.Version 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 54 with Version

use of io.fabric8.api.Version 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 55 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class FabricManager method doGetProfile.

Map<String, Object> doGetProfile(Version version, String profileId, List<String> fields, boolean mandatory) {
    Profile profile;
    if (mandatory) {
        profile = version.getRequiredProfile(profileId);
    } else {
        profile = version.getProfile(profileId);
    }
    if (profile == null) {
        return null;
    }
    Map<String, Object> answer = BeanUtils.convertProfileToMap(fabricService, profile, fields);
    String iconURLField = "iconURL";
    if (fields.contains(iconURLField) && !profile.isOverlay()) {
        // TODO this could move to Profile.getIconURL() but that would require
        // introducing profileService into ProfileImpl and the ProfileBuilder stuff
        String restApi = restApiUrl();
        if (restApi != null && restApi.length() > 0) {
            // turn REST into relative URI so it works with docker containers etc (avoids local ports etc)
            try {
                URL url = new URL(restApi);
                restApi = url.getPath();
            } catch (MalformedURLException e) {
            // Ignore
            }
            String icon = getIconURL(version, version.getId(), profile, profileId, restApi);
            answer.put(iconURLField, icon);
        }
    }
    return answer;
}
Also used : MalformedURLException(java.net.MalformedURLException) Profile(io.fabric8.api.Profile) URL(java.net.URL)

Aggregations

Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 File (java.io.File)52 Test (org.junit.Test)46 IOException (java.io.IOException)41 ArrayList (java.util.ArrayList)36 Container (io.fabric8.api.Container)35 HashMap (java.util.HashMap)34 ProfileService (io.fabric8.api.ProfileService)27 Map (java.util.Map)25 Git (org.eclipse.jgit.api.Git)22 FabricService (io.fabric8.api.FabricService)21 Version (org.osgi.framework.Version)21 ProfileBuilder (io.fabric8.api.ProfileBuilder)18 GitVersion (io.fabric8.api.commands.GitVersion)18 PatchException (io.fabric8.patch.management.PatchException)15 HashSet (java.util.HashSet)15 TreeMap (java.util.TreeMap)14 LinkedList (java.util.LinkedList)13 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)12