Search in sources :

Example 1 with MQBrokerConfigDTO

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;
}
Also used : FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException) CreateChildContainerOptions(io.fabric8.api.CreateChildContainerOptions) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) Profile(io.fabric8.api.Profile) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions)

Example 2 with MQBrokerConfigDTO

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;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile) MQBrokerStatusDTO(io.fabric8.api.jmx.MQBrokerStatusDTO) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) FabricRequirements(io.fabric8.api.FabricRequirements)

Example 3 with MQBrokerConfigDTO

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);
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with MQBrokerConfigDTO

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;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with MQBrokerConfigDTO

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;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO)

Aggregations

MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)7 ArrayList (java.util.ArrayList)5 Profile (io.fabric8.api.Profile)4 CreateContainerBasicOptions (io.fabric8.api.CreateContainerBasicOptions)2 FabricRequirements (io.fabric8.api.FabricRequirements)2 ProfileRequirements (io.fabric8.api.ProfileRequirements)2 MQBrokerStatusDTO (io.fabric8.api.jmx.MQBrokerStatusDTO)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Container (io.fabric8.api.Container)1 ContainerProvider (io.fabric8.api.ContainerProvider)1 CreateChildContainerOptions (io.fabric8.api.CreateChildContainerOptions)1 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)1 FabricAuthenticationException (io.fabric8.api.FabricAuthenticationException)1 MQService (io.fabric8.api.MQService)1 Version (io.fabric8.api.Version)1 BrokerKind (io.fabric8.api.jmx.BrokerKind)1