Search in sources :

Example 71 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class MQManager method assignProfileToContainers.

public static void assignProfileToContainers(FabricService fabricService, Profile profile, String[] assignContainers) {
    for (String containerName : assignContainers) {
        try {
            Container container = fabricService.getContainer(containerName);
            if (container == null) {
                LOG.warn("Failed to assign profile to " + containerName + ": profile doesn't exists");
            } else {
                Set<Profile> profiles = new HashSet<Profile>(Arrays.asList(container.getProfiles()));
                profiles.add(profile);
                container.setProfiles(profiles.toArray(new Profile[profiles.size()]));
                LOG.info("Profile successfully assigned to " + containerName);
            }
        } catch (Exception e) {
            LOG.warn("Failed to assign profile to " + containerName + ": " + e.getMessage());
        }
    }
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile) MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 72 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ContainerImpl method removeProfiles.

@Override
public void removeProfiles(String... profileIds) {
    List<String> removedProfiles = Arrays.asList(profileIds);
    List<Profile> updatedProfileList = new LinkedList<>();
    for (String profileId : dataStore.getContainerProfiles(id)) {
        if (!removedProfiles.contains(profileId)) {
            Profile profile = getVersion().getProfile(profileId);
            if (profile != null) {
                updatedProfileList.add(profile);
            }
        }
    }
    setProfiles(updatedProfileList.toArray(new Profile[updatedProfileList.size()]));
}
Also used : Profile(io.fabric8.api.Profile) LinkedList(java.util.LinkedList)

Example 73 with Profile

use of io.fabric8.maven.core.config.Profile 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 74 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ContainerImpl method setProfiles.

public void setProfiles(Profile[] profiles) {
    String versionId = dataStore.getContainerVersion(id);
    List<String> currentProfileIds = dataStore.getContainerProfiles(id);
    List<String> profileIds = new ArrayList<String>();
    if (profiles != null) {
        for (Profile profile : profiles) {
            IllegalArgumentAssertion.assertTrue(versionId.equals(profile.getVersion()), "Version mismatch setting profile " + profile + ", expected version " + versionId);
            IllegalArgumentAssertion.assertFalse(profile.isAbstract(), "The profile " + profile + " is abstract and can not be associated to containers");
            IllegalArgumentAssertion.assertFalse(profile.getId().matches(ENSEMBLE_PROFILE_PATTERN) && !currentProfileIds.contains(profile.getId()), "The profile " + profile + " is not assignable.");
            profileIds.add(profile.getId());
        }
    }
    if (profileIds.isEmpty()) {
        profileIds.add(ZkDefs.DEFAULT_PROFILE);
    }
    dataStore.setContainerProfiles(id, profileIds);
}
Also used : ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile)

Example 75 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricConfigAdminBridge method updateInternal.

/**
 * Method scheduled to run in separate thread - so be careful, as we may be running in deactivated SCR
 * component.
 * @throws Exception
 */
private synchronized void updateInternal() throws Exception {
    try {
        Container currentContainer = fabricService.get().getCurrentContainer();
        if (currentContainer == null) {
            LOGGER.warn("No current container yet so cannot update!");
            return;
        }
        Profile overlayProfile = null;
        try {
            overlayProfile = currentContainer.getOverlayProfile();
        } catch (RuntimeException e) {
            LOGGER.warn("No profile data yet so cannot update!");
            return;
        }
        Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService.get(), overlayProfile);
        Map<String, Map<String, String>> configurations = effectiveProfile.getConfigurations();
        List<Configuration> zkConfigs = asList(configAdmin.get().listConfigurations("(" + FABRIC_ZOOKEEPER_PID + "=*)"));
        // Process all configurations but agent
        for (String pid : configurations.keySet()) {
            if (!pid.equals(Constants.AGENT_PID)) {
                Hashtable<String, Object> c = new Hashtable<String, Object>(configurations.get(pid));
                if (!updateConfig(zkConfigs, pid, c)) {
                    return;
                }
            }
        }
        // Process agent configuration last
        for (String pid : configurations.keySet()) {
            if (pid.equals(Constants.AGENT_PID)) {
                Hashtable<String, Object> c = new Hashtable<String, Object>(configurations.get(pid));
                c.put(Profile.HASH, String.valueOf(effectiveProfile.getProfileHash()));
                if (!updateConfig(zkConfigs, pid, c)) {
                    return;
                }
            }
        }
        for (Configuration config : zkConfigs) {
            LOGGER.info("Deleting configuration {}", config.getPid());
            fabricService.get().getPortService().unregisterPort(fabricService.get().getCurrentContainer(), config.getPid());
            if (!isValid()) {
                return;
            }
            config.delete();
        }
        // end of update
        Configuration fcab = configAdmin.get().getConfiguration(Constants.CONFIGADMIN_BRIDGE_PID, null);
        Hashtable<String, String> props = new Hashtable<>();
        props.put("lastUpdate", Long.toString(new Date().getTime()));
        fcab.update(props);
    } catch (IllegalStateException e) {
        handleException(e);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Profile(io.fabric8.api.Profile) Date(java.util.Date) Container(io.fabric8.api.Container) Map(java.util.Map)

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