use of io.fabric8.api.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());
}
}
}
use of io.fabric8.api.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()]));
}
use of io.fabric8.api.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()]));
}
use of io.fabric8.api.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);
}
use of io.fabric8.api.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);
}
}
Aggregations