use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
MQBrokerConfigDTO dto = createDTO();
Profile profile = MQManager.createOrUpdateProfile(dto, fabricService, runtimeProperties);
if (profile == null) {
return null;
}
String profileId = profile.getId();
System.out.println("MQ profile " + profileId + " ready");
// assign profile to existing containers
if (assign != null) {
String[] assignContainers = assign.split(",");
MQManager.assignProfileToContainers(fabricService, profile, assignContainers);
}
// create containers
if (create != null) {
String[] createContainers = create.split(",");
List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders(dto, fabricService, "child", profileId, dto.version(), createContainers);
for (CreateContainerBasicOptions.Builder builder : builderList) {
CreateContainerMetadata[] metadatas;
try {
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
builder = childBuilder.jmxUser(username).jmxPassword(password);
}
metadatas = fabricService.createContainers(builder.build());
// check if there was a FabricAuthenticationException as failure then we can try again
if (metadatas != null) {
for (CreateContainerMetadata meta : metadatas) {
if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) {
throw (FabricAuthenticationException) meta.getFailure();
}
}
}
ShellUtils.storeFabricCredentials(session, username, password);
} catch (FabricAuthenticationException fae) {
// If authentication fails, prompts for credentials and try again.
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
promptForJmxCredentialsIfNeeded();
metadatas = fabricService.createContainers(childBuilder.jmxUser(username).jmxPassword(password).build());
ShellUtils.storeFabricCredentials(session, username, password);
}
}
}
}
return null;
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method loadBrokerStatus.
@Override
public List<MQBrokerStatusDTO> loadBrokerStatus(String versionId) throws Exception {
FabricRequirements requirements = fabricService.getRequirements();
List<MQBrokerStatusDTO> answer = new ArrayList<MQBrokerStatusDTO>();
Version version = versionId == null ? fabricService.getDefaultVersion() : profileService.getVersion(versionId);
Container[] containers = fabricService.getContainers();
List<Profile> values = getActiveOrRequiredBrokerProfileMap(version, requirements);
for (Profile profile : values) {
List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
for (MQBrokerConfigDTO configDTO : list) {
ProfileRequirements profileRequirements = requirements.findProfileRequirements(profile.getId());
int count = 0;
for (Container container : containers) {
if (Containers.containerHasProfile(container, profile)) {
MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, container);
count++;
answer.add(status);
}
}
// if there are no containers yet, lets create a record anyway
if (count == 0) {
MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, null);
answer.add(status);
}
}
}
addMasterSlaveStatus(answer);
return answer;
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method saveBrokerConfigurationJSON.
@Override
public void saveBrokerConfigurationJSON(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
List<MQBrokerConfigDTO> dtos = new ArrayList<MQBrokerConfigDTO>();
MappingIterator<Object> iter = mapper.reader(MQBrokerConfigDTO.class).readValues(json);
while (iter.hasNext()) {
Object next = iter.next();
if (next instanceof MQBrokerConfigDTO) {
dtos.add((MQBrokerConfigDTO) next);
} else {
LOG.warn("Expected MQBrokerConfigDTO but parsed invalid DTO " + next);
}
}
saveBrokerConfiguration(dtos);
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQManager method createConfigDTOs.
public static List<MQBrokerConfigDTO> createConfigDTOs(MQService mqService, Profile profile) {
List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
Map<String, Map<String, String>> configurations = profile.getConfigurations();
Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
for (Map.Entry<String, Map<String, String>> entry : entries) {
String key = entry.getKey();
Map<String, String> configuration = entry.getValue();
if (isBrokerConfigPid(key)) {
String brokerName = getBrokerNameFromPID(key);
String profileId = profile.getId();
MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
dto.setProfile(profileId);
dto.setBrokerName(brokerName);
String version = profile.getVersion();
dto.setVersion(version);
List<String> parentIds = profile.getParentIds();
if (parentIds.size() > 0) {
dto.setParentProfile(parentIds.get(0));
}
if (configuration != null) {
dto.setData(configuration.get(DATA));
dto.setConfigUrl(configuration.get(CONFIG_URL));
dto.setGroup(configuration.get(GROUP));
dto.setKind(BrokerKind.fromValue(configuration.get(KIND)));
dto.setMinimumInstances(Maps.integerValue(configuration, MINIMUM_INSTANCES));
dto.setNetworks(Maps.stringValues(configuration, NETWORKS));
dto.setNetworksUserName(configuration.get(NETWORK_USER_NAME));
dto.setNetworksPassword(configuration.get(NETWORK_PASSWORD));
dto.setReplicas(Maps.integerValue(configuration, REPLICAS));
for (Map.Entry<String, String> configurationEntry : configuration.entrySet()) {
if (configurationEntry.getKey().endsWith("-port")) {
dto.getPorts().put(configurationEntry.getKey().substring(0, configurationEntry.getKey().indexOf("-port")), configurationEntry.getValue());
}
}
}
answer.add(dto);
}
}
return answer;
}
use of io.fabric8.api.jmx.MQBrokerConfigDTO in project fabric8 by jboss-fuse.
the class MQCreateAction method createDTO.
private MQBrokerConfigDTO createDTO() {
if (Strings.isNullOrBlank(username)) {
username = ShellUtils.retrieveFabricUser(session);
}
if (Strings.isNullOrBlank(password)) {
password = ShellUtils.retrieveFabricUserPassword(session);
}
MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
if (config != null) {
dto.setConfigUrl(config);
} else {
if (nossl) {
dto.setConfigUrl("broker.xml");
} else {
dto.setConfigUrl("ssl-broker.xml");
}
}
dto.setData(data);
if (ports != null && ports.length > 0) {
for (String port : ports) {
addConfig(port, dto.getPorts());
}
}
dto.setGroup(group);
dto.setJvmOpts(jvmOpts);
dto.setBrokerName(name);
dto.setProfile(profile);
dto.setClientProfile(clientProfile);
dto.setClientParentProfile(clientParentProfile);
dto.setNetworks(networks);
dto.setNetworksPassword(networksPassword);
dto.setNetworksUserName(networksUserName);
dto.setParentProfile(parentProfile);
dto.setProperties(properties);
if (version == null) {
version = fabricService.getDefaultVersionId();
}
dto.setVersion(version);
dto.setMinimumInstances(minimumInstances);
dto.setReplicas(replicas);
dto.setSsl(!nossl);
dto.setKind(kind);
return dto;
}
Aggregations