Search in sources :

Example 31 with ProfileService

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

the class ZkDataStoreImpl method deleteContainer.

@Override
public void deleteContainer(FabricService fabricService, String containerId) {
    assertValid();
    try {
        if (curator.get() == null) {
            throw new IllegalStateException("Zookeeper service not available");
        }
        // Wipe all config entries that are related to the container for all versions.
        ProfileService profileService = fabricService.adapt(ProfileService.class);
        for (String version : profileService.getVersions()) {
            deleteSafe(curator.get(), ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(version, containerId));
        }
        deleteSafe(curator.get(), ZkPath.CONFIG_CONTAINER.getPath(containerId));
        deleteSafe(curator.get(), ZkPath.CONTAINER.getPath(containerId));
        deleteSafe(curator.get(), ZkPath.CONTAINER_ALIVE.getPath(containerId));
        deleteSafe(curator.get(), ZkPath.CONTAINER_DOMAINS.getPath(containerId));
        deleteSafe(curator.get(), ZkPath.CONTAINER_PROVISION.getPath(containerId));
        deleteSafe(curator.get(), ZkPath.CONTAINER_STATUS.getPath(containerId));
        deleteSafe(curator.get(), ZkPath.AUTHENTICATION_CONTAINER.getPath(containerId));
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) FabricException(io.fabric8.api.FabricException) InvalidClassException(java.io.InvalidClassException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 32 with ProfileService

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

the class VersionCompleter method complete.

@Override
public int complete(String buffer, int cursor, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    List<String> versions = profileService.getVersions();
    for (String version : versions) {
        delegate.getStrings().add(version);
    }
    return delegate.complete(buffer, cursor, candidates);
}
Also used : ProfileService(io.fabric8.api.ProfileService) StringsCompleter(org.apache.karaf.shell.console.completer.StringsCompleter)

Example 33 with ProfileService

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

the class FabricCommand method getProfiles.

/**
 * Gets (or creates) all the profiles for the given names.
 * <p/>
 * <b>Important:</b> If a profile does not already exists with the given name, then a new {@link Profile} is
 * created and returned in the list.
 *
 * @see #getExistingProfiles(io.fabric8.api.FabricService, io.fabric8.api.Version, java.util.List)
 */
public static Profile[] getProfiles(FabricService fabricService, Version version, List<String> names) {
    List<Profile> allProfiles = version.getProfiles();
    List<Profile> profiles = new ArrayList<>();
    if (names == null) {
        return new Profile[0];
    }
    for (String profileId : names) {
        Profile profile = null;
        for (Profile p : allProfiles) {
            if (profileId.equals(p.getId())) {
                profile = p;
                break;
            }
        }
        if (profile == null) {
            ProfileBuilder builder = ProfileBuilder.Factory.create(version.getId(), profileId);
            ProfileService profileService = fabricService.adapt(ProfileService.class);
            profile = profileService.createProfile(builder.getProfile());
        }
        profiles.add(profile);
    }
    return profiles.toArray(new Profile[profiles.size()]);
}
Also used : ProfileService(io.fabric8.api.ProfileService) ArrayList(java.util.ArrayList) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 34 with ProfileService

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

the class VersionResource method createProfile.

/**
 * Creates a new profile.
 * <br>
 * For example send this JSON to be able to create a new profile:
 *
 * <code>
 * { "id": "myNewProfile", "parents": ["containers-tomcat"] }
 * </code>
 */
@POST
public Response createProfile(ProfileDTO profileDTO) throws URISyntaxException {
    Objects.notNull(profileDTO, "profileDTO");
    FabricService fabricService = getFabricService();
    Objects.notNull(fabricService, "fabricService");
    ProfileService profileService = getProfileService();
    Objects.notNull(profileService, "profileService");
    String id = profileDTO.getId();
    if (Strings.isNullOrBlank(id)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("No id specified for the profile to be created").build();
    }
    URI location = new URI(getBaseUri() + "profile/" + id);
    // lets check it doesn't already exist
    String versionId = version.getId();
    if (profileService.hasProfile(versionId, id)) {
        return Response.seeOther(location).entity("Profile already exists for id: " + id).build();
    }
    // lets override whatever the version is set to
    profileDTO.setVersion(versionId);
    // create the profile
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, id);
    profileDTO.populateBuilder(fabricService, profileService, builder);
    Profile profile = builder.getProfile();
    profileService.createProfile(profile);
    return Response.created(location).build();
}
Also used : ProfileService(io.fabric8.api.ProfileService) FabricService(io.fabric8.api.FabricService) URI(java.net.URI) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile) POST(javax.ws.rs.POST)

Example 35 with ProfileService

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

the class AgentUtils method getProfileArtifacts.

/**
 * Returns the location and parser map (i.e. the location and the parsed maven coordinates and artifact locations) of each bundle and feature
 */
public static Map<String, Parser> getProfileArtifacts(FabricService fabricService, Profile profile, Iterable<String> bundles, Iterable<Feature> features, Callback<String> nonMavenLocationCallback) {
    Set<String> locations = new HashSet<>();
    for (Feature feature : features) {
        List<BundleInfo> bundleList = feature.getBundles();
        if (bundleList == null) {
            LOGGER.warn("No bundles for feature " + feature);
        } else {
            for (BundleInfo bundle : bundleList) {
                locations.add(bundle.getLocation());
            }
        }
    }
    for (String bundle : bundles) {
        locations.add(bundle);
    }
    Map<String, Parser> artifacts = new HashMap<>();
    for (String location : locations) {
        try {
            if (location.contains("$")) {
                ProfileService profileService = fabricService.adapt(ProfileService.class);
                Profile overlay = profileService.getOverlayProfile(profile);
                location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
            }
            if (location.startsWith("mvn:") || location.contains(":mvn:")) {
                Parser parser = Parser.parsePathWithSchemePrefix(location);
                artifacts.put(location, parser);
            } else {
                if (nonMavenLocationCallback != null) {
                    nonMavenLocationCallback.call(location);
                }
            }
        } catch (MalformedURLException e) {
            LOGGER.error("Failed to parse bundle URL: " + location + ". " + e, e);
        }
    }
    return artifacts;
}
Also used : MalformedURLException(java.net.MalformedURLException) BundleInfo(io.fabric8.agent.model.BundleInfo) ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile) HashSet(java.util.HashSet) Parser(io.fabric8.maven.util.Parser)

Aggregations

ProfileService (io.fabric8.api.ProfileService)36 Profile (io.fabric8.api.Profile)22 Version (io.fabric8.api.Version)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 FabricService (io.fabric8.api.FabricService)7 Map (java.util.Map)6 Parser (io.fabric8.maven.util.Parser)5 File (java.io.File)5 HashSet (java.util.HashSet)5 ProfileBuilder (io.fabric8.api.ProfileBuilder)4 DownloadManager (io.fabric8.agent.download.DownloadManager)3 Feature (io.fabric8.agent.model.Feature)3 MalformedURLException (java.net.MalformedURLException)3 Container (io.fabric8.api.Container)2 ProfileRequirements (io.fabric8.api.ProfileRequirements)2 IOException (java.io.IOException)2 URL (java.net.URL)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2