func BuildElasticsearchTopology()

in pkg/api/deploymentapi/depresourceapi/elasticsearch_topology.go [146:172]


func BuildElasticsearchTopology(params BuildElasticsearchTopologyParams) ([]*models.ElasticsearchClusterTopologyElement, error) {
	var topologyList []*models.ElasticsearchClusterTopologyElement
	for _, desired := range params.Topology {
		for _, t := range params.ClusterTopology {
			if matchNodeType(*t.NodeType, desired) {
				// Override the desired topology if values are non zero
				if desired.Size > 0 {
					t.Size.Value = ec.Int32(desired.Size)
				}
				if desired.ZoneCount > 0 {
					t.ZoneCount = desired.ZoneCount
				}

				topologyList = append(topologyList, t)
			}
		}
	}

	if len(topologyList) == 0 {
		return nil, fmt.Errorf(
			"deployment topology: failed to obtain desired topology names (%+v) in deployment template id \"%s\"",
			params.Topology, params.TemplateID,
		)
	}

	return topologyList, nil
}