Search in sources :

Example 1 with StackServiceComponentDescriptor

use of com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor in project cloudbreak by hortonworks.

the class AppConfig method createServiceComponentDescriptors.

private StackServiceComponentDescriptors createServiceComponentDescriptors(String stackServiceComponentsJson, Map<String, Integer> minCardinalityReps, Map<String, Integer> maxCardinalityReps) throws Exception {
    Map<String, StackServiceComponentDescriptor> stackServiceComponentDescriptorMap = Maps.newHashMap();
    JsonNode rootNode = JsonUtil.readTree(stackServiceComponentsJson);
    JsonNode itemsNode = rootNode.get("items");
    for (JsonNode itemNode : itemsNode) {
        JsonNode componentsNode = itemNode.get("components");
        for (JsonNode componentNode : componentsNode) {
            JsonNode stackServiceComponentsNode = componentNode.get("StackServiceComponents");
            String componentName = stackServiceComponentsNode.get("component_name").asText();
            String componentCategory = stackServiceComponentsNode.get("component_category").asText();
            int minCardinality = parseCardinality(minCardinalityReps, stackServiceComponentsNode.get("cardinality").asText(), 0);
            int maxCardinality = parseCardinality(maxCardinalityReps, stackServiceComponentsNode.get("cardinality").asText(), Integer.MAX_VALUE);
            stackServiceComponentDescriptorMap.put(componentName, new StackServiceComponentDescriptor(componentName, componentCategory, minCardinality, maxCardinality));
        }
    }
    return new StackServiceComponentDescriptors(stackServiceComponentDescriptorMap);
}
Also used : StackServiceComponentDescriptors(com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptors) StackServiceComponentDescriptor(com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with StackServiceComponentDescriptor

use of com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor in project cloudbreak by hortonworks.

the class ClusterToClusterResponseConverter method prepareServiceEndpointsMap.

private Map<String, String> prepareServiceEndpointsMap(Cluster cluster, String ambariIp) {
    Set<HostGroup> hostGroups = cluster.getHostGroups();
    Blueprint blueprint = cluster.getBlueprint();
    Map<String, String> result = new HashMap<>();
    List<Port> ports = NetworkUtils.getPorts(Optional.empty());
    try {
        JsonNode hostGroupsNode = blueprintValidator.getHostGroupNode(blueprint);
        Map<String, HostGroup> hostGroupMap = blueprintValidator.createHostGroupMap(hostGroups);
        for (JsonNode hostGroupNode : hostGroupsNode) {
            String hostGroupName = blueprintValidator.getHostGroupName(hostGroupNode);
            JsonNode componentsNode = blueprintValidator.getComponentsNode(hostGroupNode);
            HostGroup actualHostgroup = hostGroupMap.get(hostGroupName);
            String serviceAddress;
            if (actualHostgroup.getConstraint().getInstanceGroup() != null) {
                InstanceMetaData next = actualHostgroup.getConstraint().getInstanceGroup().getInstanceMetaData().iterator().next();
                serviceAddress = next.getPublicIpWrapper();
            } else {
                serviceAddress = actualHostgroup.getHostMetadata().iterator().next().getHostName();
            }
            for (JsonNode componentNode : componentsNode) {
                String componentName = componentNode.get("name").asText();
                StackServiceComponentDescriptor componentDescriptor = stackServiceComponentDescs.get(componentName);
                collectServicePorts(result, ports, ambariIp, serviceAddress, componentDescriptor, cluster);
            }
        }
    } catch (Exception ignored) {
        return result;
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Port(com.sequenceiq.cloudbreak.api.model.Port) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) JsonNode(com.fasterxml.jackson.databind.JsonNode) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) IOException(java.io.IOException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) StackServiceComponentDescriptor(com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor)

Example 3 with StackServiceComponentDescriptor

use of com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor in project cloudbreak by hortonworks.

the class ClusterToClusterResponseConverterTest method testConvertWithoutMasterComponent.

@Test
public void testConvertWithoutMasterComponent() throws IOException {
    // GIVEN
    mockAll();
    given(stackServiceComponentDescs.get(anyString())).willReturn(new StackServiceComponentDescriptor("dummy", "dummy", 1, 1));
    // WHEN
    ClusterResponse result = underTest.convert(getSource());
    // THEN
    assertEquals(1L, (long) result.getId());
}
Also used : StackServiceComponentDescriptor(com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) Test(org.junit.Test)

Aggregations

StackServiceComponentDescriptor (com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptor)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)1 Port (com.sequenceiq.cloudbreak.api.model.Port)1 StackServiceComponentDescriptors (com.sequenceiq.cloudbreak.blueprint.validation.StackServiceComponentDescriptors)1 CloudbreakApiException (com.sequenceiq.cloudbreak.controller.CloudbreakApiException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1