Пример #1
0
func (s *Store) FindChildService(ctx datastore.Context, deploymentID, parentID, serviceName string) (*Service, error) {
	parentID = strings.TrimSpace(parentID)

	if deploymentID = strings.TrimSpace(deploymentID); deploymentID == "" {
		return nil, errors.New("empty deployment ID not allowed")
	} else if serviceName = strings.TrimSpace(serviceName); serviceName == "" {
		return nil, errors.New("empty service name not allowed")
	}

	search := search.Search("controlplane").Type(kind).Filter(
		"and",
		search.Filter().Terms("DeploymentID", deploymentID),
		search.Filter().Terms("ParentServiceID", parentID),
		search.Filter().Terms("Name", serviceName),
	)

	q := datastore.NewQuery(ctx)
	results, err := q.Execute(search)
	if err != nil {
		return nil, err
	}

	if results.Len() == 0 {
		return nil, nil
	} else if svcs, err := convert(results); err != nil {
		return nil, err
	} else {
		return &svcs[0], nil
	}
}
Пример #2
0
func (s *Store) FindAssignmentByHostPort(ctx datastore.Context, ipAddr string, port uint16) (*AddressAssignment, error) {
	if ipAddr = strings.TrimSpace(ipAddr); ipAddr == "" {
		return nil, fmt.Errorf("hostIP cannot be empty")
	} else if port == 0 {
		return nil, fmt.Errorf("port must be greater than 0")
	}

	search := search.Search("controlplane").Type(kind).Filter(
		"and",
		search.Filter().Terms("IPAddr", ipAddr),
		search.Filter().Terms("Port", strconv.FormatUint(uint64(port), 10)),
	)

	if results, err := datastore.NewQuery(ctx).Execute(search); err != nil {
		return nil, err
	} else if output, err := convert(results); err != nil {
		return nil, err
	} else if len(output) == 0 {
		return nil, nil
	} else {
		return &output[0], nil
	}
}
Пример #3
0
func (s *Store) FindAssignmentByServiceEndpoint(ctx datastore.Context, serviceID, endpointName string) (*AddressAssignment, error) {
	if serviceID = strings.TrimSpace(serviceID); serviceID == "" {
		return nil, fmt.Errorf("service ID cannot be empty")
	} else if endpointName = strings.TrimSpace(endpointName); endpointName == "" {
		return nil, fmt.Errorf("endpoint name cannot be empty")
	}

	search := search.Search("controlplane").Type(kind).Filter(
		"and",
		search.Filter().Terms("ServiceID", serviceID),
		search.Filter().Terms("EndpointName", endpointName),
	)

	if results, err := datastore.NewQuery(ctx).Execute(search); err != nil {
		return nil, err
	} else if output, err := convert(results); err != nil {
		return nil, err
	} else if len(output) == 0 {
		return nil, nil
	} else {
		return &output[0], nil
	}
}