Search in sources :

Example 11 with Profile

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

the class JavaContainers method getJavaContainerArtifacts.

public static Map<String, Parser> getJavaContainerArtifacts(FabricService fabric, List<Profile> profileList, DownloadManager downloadManager) throws Exception {
    Map<String, Parser> artifacts = new TreeMap<String, Parser>();
    for (Profile profile : profileList) {
        Map<String, Parser> profileArtifacts = AgentUtils.getProfileArtifacts(fabric, downloadManager, profile);
        artifacts.putAll(profileArtifacts);
        appendMavenDependencies(artifacts, profile);
    }
    return artifacts;
}
Also used : TreeMap(java.util.TreeMap) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser)

Example 12 with Profile

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

the class ProjectDeployerImpl method deployProject.

@Override
public DeployResults deployProject(ProjectRequirements requirements, boolean merge) throws Exception {
    Version version = getOrCreateVersion(requirements);
    // validate that all the parent profiles exists
    for (String parent : requirements.getParentProfiles()) {
        if (!version.hasProfile(parent)) {
            throw new IllegalArgumentException("Parent profile " + parent + " does not exists in version " + version.getId());
        }
    }
    Profile profile = getOrCreateProfile(version, requirements);
    boolean isAbstract = requirements.isAbstractProfile();
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    builder.addAttribute(Profile.ABSTRACT, "" + isAbstract);
    ProjectRequirements oldRequirements = writeRequirementsJson(requirements, profile, builder);
    updateProfileConfiguration(version, profile, requirements, oldRequirements, builder, merge);
    return resolveProfileDeployments(requirements, fabricService.get(), profile, builder, merge);
}
Also used : Version(io.fabric8.api.Version) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 13 with Profile

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

the class ProjectDeployerImpl method writeRequirementsJson.

private ProjectRequirements writeRequirementsJson(ProjectRequirements requirements, Profile profile, ProfileBuilder builder) throws IOException {
    ObjectMapper mapper = DtoHelper.getMapper();
    byte[] json = mapper.writeValueAsBytes(requirements);
    String fileName = DtoHelper.getRequirementsConfigFileName(requirements);
    // lets read the previous requirements if there are any
    ProfileRegistry profileRegistry = fabricService.get().adapt(ProfileRegistry.class);
    byte[] oldData = profile.getFileConfiguration(fileName);
    LOG.info("Writing file " + fileName + " to profile " + profile);
    builder.addFileConfiguration(fileName, json);
    if (oldData == null || oldData.length == 0) {
        return null;
    } else {
        return mapper.reader(ProjectRequirements.class).readValue(oldData);
    }
}
Also used : ProfileRegistry(io.fabric8.api.ProfileRegistry) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with Profile

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

the class ProjectDeployerImpl method resolveProfileDeployments.

private DeployResults resolveProfileDeployments(ProjectRequirements requirements, FabricService fabric, Profile profile, ProfileBuilder builder, boolean mergeWithOldProfile) throws Exception {
    DependencyDTO rootDependency = requirements.getRootDependency();
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    if (!mergeWithOldProfile) {
        // If we're not merging with the old profile, then create a dummy empty profile to merge with instead.
        ProfileBuilder emptyProfile = ProfileBuilder.Factory.create(profile.getVersion(), profile.getId()).setOverlay(true);
        profile = emptyProfile.getProfile();
    }
    if (rootDependency != null) {
        // as a hack lets just add this bundle in
        LOG.info("Got root: " + rootDependency);
        List<String> parentIds = profile.getParentIds();
        Profile overlay = profileService.getOverlayProfile(profile);
        String bundleUrl = rootDependency.toBundleUrlWithType();
        LOG.info("Using resolver to add extra features and bundles on " + bundleUrl);
        List<String> features = new ArrayList<String>(profile.getFeatures());
        List<String> bundles = new ArrayList<String>(profile.getBundles());
        List<String> optionals = new ArrayList<String>(profile.getOptionals());
        if (requirements.getFeatures() != null) {
            features.addAll(requirements.getFeatures());
        }
        if (requirements.getBundles() != null) {
            bundles.addAll(requirements.getBundles());
        }
        bundles.add(bundleUrl);
        LOG.info("Adding bundle: " + bundleUrl);
        // TODO we maybe should detect a karaf based container in a nicer way than this?
        boolean isKarafContainer = parentIds.contains("karaf") || parentIds.contains("containers-karaf");
        boolean addBundleDependencies = Objects.equal("bundle", rootDependency.getType()) || isKarafContainer;
        if (addBundleDependencies && requirements.isUseResolver()) {
            // lets build up a list of all current active features and bundles along with all discovered features
            List<Feature> availableFeatures = new ArrayList<Feature>();
            addAvailableFeaturesFromProfile(availableFeatures, fabric, overlay);
            Set<String> currentBundleLocations = new HashSet<>();
            currentBundleLocations.addAll(bundles);
            // lets add the current features
            DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabric, executorService);
            Set<Feature> currentFeatures = AgentUtils.getFeatures(fabric, downloadManager, overlay);
            addBundlesFromProfile(currentBundleLocations, overlay);
            List<String> parentProfileIds = requirements.getParentProfiles();
            if (parentProfileIds != null) {
                for (String parentProfileId : parentProfileIds) {
                    Profile parentProfile = profileService.getProfile(profile.getVersion(), parentProfileId);
                    Profile parentOverlay = profileService.getOverlayProfile(parentProfile);
                    Set<Feature> parentFeatures = AgentUtils.getFeatures(fabric, downloadManager, parentOverlay);
                    currentFeatures.addAll(parentFeatures);
                    addAvailableFeaturesFromProfile(availableFeatures, fabric, parentOverlay);
                    addBundlesFromProfile(currentBundleLocations, parentOverlay);
                }
            }
            // lets add all known features from the known repositories
            for (DependencyDTO dependency : rootDependency.getChildren()) {
                if ("test".equals(dependency.getScope()) || "provided".equals(dependency.getScope())) {
                    continue;
                }
                if ("jar".equals(dependency.getType())) {
                    String match = getAllServiceMixBundles().get(dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion());
                    if (match != null) {
                        LOG.info("Replacing artifact " + dependency + " with servicemix bundle " + match);
                        String[] parts = match.split(":");
                        dependency.setGroupId(parts[0]);
                        dependency.setArtifactId(parts[1]);
                        dependency.setVersion(parts[2]);
                        dependency.setType("bundle");
                    }
                }
                String prefix = dependency.toBundleUrlWithoutVersion();
                Feature feature = findFeatureWithBundleLocationPrefix(currentFeatures, prefix);
                if (feature != null) {
                    LOG.info("Feature is already is in the profile " + feature.getId() + " for " + dependency.toBundleUrl());
                } else {
                    feature = findFeatureWithBundleLocationPrefix(availableFeatures, prefix);
                    if (feature != null) {
                        String name = feature.getName();
                        if (features.contains(name)) {
                            LOG.info("Feature is already added " + name + " for " + dependency.toBundleUrl());
                        } else {
                            LOG.info("Found a matching feature for bundle " + dependency.toBundleUrl() + ": " + feature.getId());
                            features.add(name);
                        }
                    } else {
                        String bundleUrlWithType = dependency.toBundleUrlWithType();
                        String foundBundleUri = findBundleUri(currentBundleLocations, prefix);
                        if (foundBundleUri != null) {
                            LOG.info("Bundle already included " + foundBundleUri + " for " + bundleUrlWithType);
                        } else {
                            boolean ignore = false;
                            String bundleWithoutMvnPrefix = getMavenCoords(bundleUrlWithType);
                            for (String ignoreBundlePrefix : RESOLVER_IGNORE_BUNDLE_PREFIXES) {
                                if (bundleWithoutMvnPrefix.startsWith(ignoreBundlePrefix)) {
                                    ignore = true;
                                    break;
                                }
                            }
                            if (ignore) {
                                LOG.info("Ignoring bundle: " + bundleUrlWithType);
                            } else {
                                boolean optional = dependency.isOptional();
                                LOG.info("Adding " + (optional ? "optional " : "") + " bundle: " + bundleUrlWithType);
                                if (optional) {
                                    optionals.add(bundleUrlWithType);
                                } else {
                                    bundles.add(bundleUrlWithType);
                                }
                            }
                        }
                    }
                }
            }
            // Modify the profile through the {@link ProfileBuilder}
            builder.setOptionals(optionals).setFeatures(features);
        }
        builder.setBundles(bundles);
    }
    profile = profileService.updateProfile(builder.getProfile());
    Integer minimumInstances = requirements.getMinimumInstances();
    if (minimumInstances != null) {
        FabricRequirements fabricRequirements = fabricService.get().getRequirements();
        ProfileRequirements profileRequirements = fabricRequirements.getOrCreateProfileRequirement(profile.getId());
        profileRequirements.setMinimumInstances(minimumInstances);
        fabricRequirements.setVersion(requirements.getVersion());
        fabricService.get().setRequirements(fabricRequirements);
    }
    // lets find a hawtio profile and version
    String profileUrl = findHawtioUrl(fabric);
    if (profileUrl == null) {
        profileUrl = "/";
    }
    if (!profileUrl.endsWith("/")) {
        profileUrl += "/";
    }
    String profilePath = Profiles.convertProfileIdToPath(profile.getId());
    profileUrl += "index.html#/wiki/branch/" + profile.getVersion() + "/view/fabric/profiles/" + profilePath;
    return new DeployResults(profile, profileUrl);
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) DeployResults(io.fabric8.deployer.dto.DeployResults) ArrayList(java.util.ArrayList) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) ProfileBuilder(io.fabric8.api.ProfileBuilder) Feature(io.fabric8.agent.model.Feature) DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) ProfileService(io.fabric8.api.ProfileService) FabricRequirements(io.fabric8.api.FabricRequirements) HashSet(java.util.HashSet)

Example 15 with Profile

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

the class ProjectDeployerImpl method getOrCreateProfile.

// Implementation methods
// -------------------------------------------------------------------------
private Profile getOrCreateProfile(Version version, ProjectRequirements requirements) {
    String profileId = getProfileId(requirements);
    if (Strings.isEmpty(profileId)) {
        throw new IllegalArgumentException("No profile ID could be deduced for requirements: " + requirements);
    }
    // make sure the profileId is valid
    FabricValidations.validateProfileName(profileId);
    Profile profile;
    if (!version.hasProfile(profileId)) {
        LOG.info("Creating new profile " + profileId + " version " + version + " for requirements: " + requirements);
        String versionId = version.getId();
        ProfileService profileService = fabricService.get().adapt(ProfileService.class);
        ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
        profile = profileService.createProfile(builder.getProfile());
    } else {
        profile = version.getRequiredProfile(profileId);
    }
    return profile;
}
Also used : ProfileService(io.fabric8.api.ProfileService) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Aggregations

Profile (io.fabric8.api.Profile)125 Version (io.fabric8.api.Version)50 Container (io.fabric8.api.Container)49 ArrayList (java.util.ArrayList)37 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Test (org.junit.Test)32 FabricService (io.fabric8.api.FabricService)28 HashMap (java.util.HashMap)25 File (java.io.File)24 ProfileService (io.fabric8.api.ProfileService)23 Map (java.util.Map)22 IOException (java.io.IOException)19 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 HashSet (java.util.HashSet)12 GitVersion (io.fabric8.api.commands.GitVersion)11 FabricRequirements (io.fabric8.api.FabricRequirements)10 LinkedList (java.util.LinkedList)9 TreeMap (java.util.TreeMap)9 LockHandle (io.fabric8.api.LockHandle)8 Parser (io.fabric8.maven.util.Parser)8