use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method createStatusDTO.
protected MQBrokerStatusDTO createStatusDTO(Profile profile, MQBrokerConfigDTO configDTO, ProfileRequirements profileRequirements, Container container) {
MQBrokerStatusDTO answer = new MQBrokerStatusDTO(configDTO);
if (container != null) {
answer.setContainer(container.getId());
answer.setAlive(container.isAlive());
answer.setProvisionResult(container.getProvisionResult());
answer.setProvisionStatus(container.getProvisionStatus());
answer.setJolokiaUrl(container.getJolokiaUrl());
}
if (profileRequirements != null) {
Integer minimumInstances = profileRequirements.getMinimumInstances();
if (minimumInstances != null) {
answer.setMinimumInstances(minimumInstances);
}
}
return answer;
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method loadBrokerConfiguration.
@Override
public List<MQBrokerConfigDTO> loadBrokerConfiguration() {
List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
Collection<Profile> values = getActiveOrRequiredBrokerProfileMap();
for (Profile profile : values) {
List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
answer.addAll(list);
}
return answer;
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method createOrUpdateProfile.
/**
* Creates or updates the broker profile for the given DTO and updates the requirements so that the
* minimum number of instances of the profile is updated
*/
public static Profile createOrUpdateProfile(MQBrokerConfigDTO dto, FabricService fabricService, RuntimeProperties runtimeProperties) throws IOException {
FabricRequirements requirements = fabricService.getRequirements();
MQService mqService = createMQService(fabricService, runtimeProperties);
Map<String, String> configuration = new HashMap<String, String>();
List<String> properties = dto.getProperties();
String version = dto.version();
boolean changeInCurrentVersion = requirements.getVersion().equals(dto.getVersion());
if (properties != null) {
for (String entry : properties) {
String[] parts = entry.split("=", 2);
if (parts.length == 2) {
configuration.put(parts[0], parts[1]);
} else {
configuration.put(parts[0], "");
}
}
}
String data = dto.getData();
String profileName = dto.profile();
try {
FabricValidations.validateProfileName(profileName);
} 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 null;
}
String brokerName = dto.getBrokerName();
if (data == null) {
// lets use a relative path so we work on any karaf container
data = "${runtime.data}" + brokerName;
}
configuration.put(DATA, data);
for (Map.Entry<String, String> port : dto.getPorts().entrySet()) {
configuration.put(port.getKey() + "-port", port.getValue());
}
BrokerKind kind = dto.kind();
configuration.put(KIND, kind.toString());
String config = dto.getConfigUrl();
if (config != null) {
configuration.put(CONFIG_URL, mqService.getConfig(version, config));
}
String group = dto.getGroup();
if (group != null) {
configuration.put(GROUP, group);
}
Maps.setStringValues(configuration, NETWORKS, dto.getNetworks());
String networksUserName = dto.getNetworksUserName();
if (networksUserName != null) {
configuration.put(NETWORK_USER_NAME, networksUserName);
}
String networksPassword = dto.getNetworksPassword();
if (networksPassword != null) {
configuration.put(NETWORK_PASSWORD, networksPassword);
}
String parentProfile = dto.getParentProfile();
if (parentProfile != null) {
configuration.put(PARENT, parentProfile);
}
Boolean ssl = dto.getSsl();
if (ssl != null) {
configuration.put(SSL, ssl.toString());
}
Integer replicas = dto.getReplicas();
if (replicas != null) {
configuration.put(REPLICAS, replicas.toString());
}
Integer minInstances = dto.getMinimumInstances();
if (minInstances != null) {
configuration.put(MINIMUM_INSTANCES, minInstances.toString());
}
Profile profile = mqService.createOrUpdateMQProfile(version, profileName, brokerName, configuration, dto.kind().equals(BrokerKind.Replicated));
String profileId = profile.getId();
ProfileRequirements profileRequirement = requirements.getOrCreateProfileRequirement(profileId);
Integer minimumInstances = profileRequirement.getMinimumInstances();
// lets reload the DTO as we may have inherited some values from the parent profile
List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
// lets assume 2 required instances for master/slave unless folks use
// N+1 or replicated
int requiredInstances = 2;
if (list.size() == 1) {
MQBrokerConfigDTO loadedDTO = list.get(0);
requiredInstances = loadedDTO.requiredInstances();
} else {
// assume N+1 broker as there's more than one broker in the profile; so lets set the required size to N+1
requiredInstances = list.size() + 1;
}
if (changeInCurrentVersion && (minimumInstances == null || minimumInstances.intValue() < requiredInstances)) {
profileRequirement.setMinimumInstances(requiredInstances);
fabricService.setRequirements(requirements);
}
String clientProfile = dto.clientProfile();
if (Strings.isNotBlank(clientProfile)) {
String clientParentProfile = dto.getClientParentProfile();
if (Strings.isNullOrBlank(clientParentProfile)) {
clientParentProfile = "mq-client-base";
}
mqService.createOrUpdateMQClientProfile(version, clientProfile, group, clientParentProfile);
}
return profile;
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method createContainerBuilders.
/**
* Creates container builders for the given DTO
*/
public static List<CreateContainerBasicOptions.Builder> createContainerBuilders(MQBrokerConfigDTO dto, FabricService fabricService, String containerProviderScheme, String profileId, String version, String[] createContainers) throws IOException {
ContainerProvider containerProvider = fabricService.getProvider(containerProviderScheme);
Objects.notNull(containerProvider, "No ContainerProvider available for scheme: " + containerProviderScheme);
if (!containerProvider.isValidProvider()) {
throw new IllegalArgumentException("ContainerProvider for scheme: " + containerProviderScheme + " is not valid in current environment");
}
List<CreateContainerBasicOptions.Builder> containerBuilders = new ArrayList<CreateContainerBasicOptions.Builder>();
for (String container : createContainers) {
String type = null;
String parent = fabricService.getCurrentContainerName();
String jvmOpts = dto.getJvmOpts();
CreateContainerBasicOptions.Builder builder = containerProvider.newBuilder();
builder = (CreateContainerBasicOptions.Builder) builder.name(container).parent(parent).number(dto.requiredInstances()).ensembleServer(false).proxyUri(fabricService.getMavenRepoURI()).jvmOpts(jvmOpts).zookeeperUrl(fabricService.getZookeeperUrl()).zookeeperPassword(fabricService.getZookeeperPassword()).profiles(profileId).version(version);
containerBuilders.add(builder);
}
return containerBuilders;
}
Aggregations