Search in sources :

Example 86 with FabricService

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

the class ProfileDownloader method addMavenBundles.

protected void addMavenBundles(FabricService fabricService, Profile profile, Set<String> bundles, List<String> bundleList) {
    for (String bundle : bundleList) {
        if (bundle != null) {
            if (bundle.contains("$")) {
                // use similar logic as io.fabric8.agent.utils.AgentUtils.getProfileArtifacts method
                // as we need to substitute version placeholders
                ProfileService profileService = fabricService.adapt(ProfileService.class);
                Profile overlay = profileService.getOverlayProfile(profile);
                bundle = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), bundle);
            }
            bundles.add(bundle);
        }
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) Profile(io.fabric8.api.Profile)

Example 87 with FabricService

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

the class ProfileDownloadArtifactsAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Version ver = version != null ? profileService.getVersion(version) : fabricService.getDefaultVersion();
    if (ver == null) {
        if (version != null) {
            System.out.println("version " + version + " does not exist!");
        } else {
            System.out.println("No default version available!");
        }
        return null;
    }
    if (target == null) {
        String karafBase = System.getProperty("karaf.base", ".");
        target = new File(karafBase, ProfileDownloadArtifactsAction.DEFAULT_TARGET);
    }
    target.mkdirs();
    if (!target.exists()) {
        System.out.println("Could not create the target directory " + target);
        return null;
    }
    if (!target.isDirectory()) {
        System.out.println("Target is not a directory " + target);
        return null;
    }
    if (executorService == null) {
        if (threadPoolSize > 1) {
            executorService = Executors.newScheduledThreadPool(threadPoolSize);
        } else {
            executorService = Executors.newSingleThreadScheduledExecutor();
        }
    }
    ProfileDownloader downloader = new ProfileDownloader(fabricService, target, force, executorService);
    downloader.setStopOnFailure(stopOnFailure);
    // we do not want to download the files from within the profile itself, only the dependencies
    downloader.setDownloadFilesFromProfile(false);
    if (verbose) {
        downloader.setListener(new ProgressIndicator());
    }
    if (profile != null) {
        Profile profileObject = null;
        if (ver.hasProfile(profile)) {
            profileObject = ver.getRequiredProfile(profile);
        }
        if (profileObject == null) {
            System.out.println("Source profile " + profile + " not found.");
            return null;
        }
        downloader.downloadProfile(profileObject);
    } else {
        downloader.downloadVersion(ver);
    }
    List<String> failedProfileIDs = downloader.getFailedProfileIDs();
    System.out.println("Downloaded " + downloader.getProcessedFileCount() + " file(s) to " + target);
    if (failedProfileIDs.size() > 0) {
        System.out.println("Failed to download these profiles: " + failedProfileIDs + ". Check the logs for details");
    }
    return null;
}
Also used : Version(io.fabric8.api.Version) ProfileDownloader(io.fabric8.agent.download.ProfileDownloader) File(java.io.File) Profile(io.fabric8.api.Profile)

Example 88 with FabricService

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

the class ProfileCopyAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // but validate the target name
    try {
        FabricValidations.validateProfileName(target);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    Version version = versionParam != null ? profileService.getRequiredVersion(versionParam) : fabricService.getRequiredDefaultVersion();
    String versionId = version.getId();
    if (!version.hasProfile(source)) {
        System.out.println("Source profile " + source + " not found.");
        return 1;
    } else if (version.hasProfile(target)) {
        if (!force) {
            System.out.println("Target profile " + target + " already exists. Use --force if you want to overwrite.");
            return null;
        }
    }
    Profiles.copyProfile(fabricService, versionId, source, target, force);
    return null;
}
Also used : Version(io.fabric8.api.Version)

Example 89 with FabricService

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

the class ProfileCreateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileId);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    if (versionId != null) {
        profileService.getRequiredVersion(versionId);
    } else {
        versionId = fabricService.getDefaultVersionId();
    }
    // we can only use existing parent profiles
    Profile[] parents = FabricCommand.getExistingProfiles(fabricService, versionId, this.parents);
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
    for (Profile parent : parents) {
        builder.addParent(parent.getId());
    }
    profileService.createProfile(builder.getProfile());
    return null;
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 90 with FabricService

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

the class ProfileDeleteAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // do not validate the name in case a profile was created somehow with invalid name
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    boolean deleted = false;
    for (Profile profile : version.getProfiles()) {
        String versionId = profile.getVersion();
        String profileId = profile.getId();
        if (name.equals(profileId)) {
            profileService.deleteProfile(fabricService, versionId, profileId, force);
            deleted = true;
        }
    }
    if (!deleted) {
        System.out.println("Profile " + name + " not found.");
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7