Search in sources :

Example 16 with ProfileService

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

the class ContainerImpl method addProfiles.

@Override
public void addProfiles(Profile... profiles) {
    List<Profile> addedProfiles = Arrays.asList(profiles);
    List<Profile> updatedProfileList = new LinkedList<Profile>();
    for (Profile p : getProfiles()) {
        updatedProfileList.add(p);
    }
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    for (Profile addedProfile : addedProfiles) {
        String versionId = addedProfile.getVersion();
        String profileId = addedProfile.getId();
        if (!profileService.hasProfile(versionId, profileId)) {
            throw new IllegalArgumentException("Profile " + profileId + " doesn't exist.");
        } else if (!updatedProfileList.contains(addedProfile)) {
            updatedProfileList.add(addedProfile);
        }
    }
    setProfiles(updatedProfileList.toArray(new Profile[updatedProfileList.size()]));
}
Also used : ProfileService(io.fabric8.api.ProfileService) Profile(io.fabric8.api.Profile) LinkedList(java.util.LinkedList)

Example 17 with ProfileService

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

the class ContainerImpl method getVersion.

@Override
public Version getVersion() {
    String versionId = dataStore.getContainerVersion(id);
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    return versionId != null ? profileService.getVersion(versionId) : null;
}
Also used : ProfileService(io.fabric8.api.ProfileService)

Example 18 with ProfileService

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

the class ProfileWatcherImpl method findProfileArifacts.

// For each profile and version return the map of bundle locations to parsers
private Map<ProfileVersionKey, Map<String, Parser>> findProfileArifacts() throws Exception {
    Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = new HashMap<ProfileVersionKey, Map<String, Parser>>();
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService.get(), executorService);
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        Profile[] profiles = container.getProfiles();
        boolean javaOrProcessContainer = ChildContainers.isJavaOrProcessContainer(fabricService.get(), container);
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            Profile overlay = profileService.getOverlayProfile(profile);
            ProfileVersionKey key = new ProfileVersionKey(profile);
            // if (!profileArtifacts.containsKey(key)) {
            Map<String, Parser> artifacts = null;
            if (javaOrProcessContainer) {
                List<Profile> singletonList = Collections.singletonList(profile);
                artifacts = JavaContainers.getJavaContainerArtifacts(fabricService.get(), singletonList, executorService);
            } else {
                artifacts = AgentUtils.getProfileArtifacts(fabricService.get(), downloadManager, overlay);
            }
            if (artifacts != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Profile " + profile.getId() + " maps to artefacts: " + artifacts.keySet());
                }
                profileArtifacts.put(key, artifacts);
            }
        // }
        }
    }
    return profileArtifacts;
}
Also used : HashMap(java.util.HashMap) DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser) Container(io.fabric8.api.Container) ProfileService(io.fabric8.api.ProfileService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with ProfileService

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

the class ProfileMetadata method findMetadataForProfile.

protected void findMetadataForProfile(String versionId, String profileId, MetadataHandler handler) throws Exception {
    FabricService service = fabricService.get();
    Objects.notNull(service, "FabricService");
    ProfileService profileService = service.adapt(ProfileService.class);
    Objects.notNull(profileService, "ProfileService");
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(service, executorService);
    Objects.notNull(downloadManager, "DownloadManager");
    Profile immediateProfile = profileService.getProfile(versionId, profileId);
    Objects.notNull(immediateProfile, "Profile for versionId: " + versionId + ", profileId: " + profileId);
    Profile profile = profileService.getOverlayProfile(immediateProfile);
    Set<String> pids = new HashSet<>();
    Map<String, File> fileMap = AgentUtils.downloadProfileArtifacts(service, downloadManager, profile);
    Set<Map.Entry<String, File>> entries = fileMap.entrySet();
    for (Map.Entry<String, File> entry : entries) {
        String uri = entry.getKey();
        File file = entry.getValue();
        if (!file.exists() || !file.isFile()) {
            LOG.warn("File " + file + " is not an existing file for " + uri + ". Ignoring");
            continue;
        }
        addMetaTypeInformation(handler, uri, file);
        pids.add(uri);
    }
    // lets check if the MetaType folder exists
    if (metaTypeFolder != null && metaTypeFolder.exists() && metaTypeFolder.isDirectory()) {
        Set<String> configurationFileNames = profile.getConfigurationFileNames();
        for (String configName : configurationFileNames) {
            if (configName.endsWith(PROPERTIES_SUFFIX) && configName.indexOf('/') < 0) {
                String pid = configName.substring(0, configName.length() - PROPERTIES_SUFFIX.length());
                addMetaTypeInformation(pids, handler, pid);
                String factoryPid = getFactoryPid(pid);
                addMetaTypeInformation(pids, handler, factoryPid);
            }
        }
    }
}
Also used : DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) JarEntry(java.util.jar.JarEntry) ProfileService(io.fabric8.api.ProfileService) FabricService(io.fabric8.api.FabricService) JarFile(java.util.jar.JarFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 20 with ProfileService

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

the class FabricResource method version.

/**
 * Accesses a version resource
 */
@Path("version/{versionId}")
public VersionResource version(@PathParam("versionId") String versionId) {
    FabricService fabricService = getFabricService();
    if (fabricService != null && Strings.isNotBlank(versionId)) {
        ProfileService profileService = fabricService.adapt(ProfileService.class);
        Version version = profileService.getRequiredVersion(versionId);
        if (version != null) {
            return new VersionResource(this, version);
        } else {
            LOG.warn("No version found for: {}", version);
        }
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path)

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