Skip to content

Commit

Permalink
Merge pull request #7224 from TheThingsNetwork/feature/fetch-dev-info…
Browse files Browse the repository at this point in the history
…-with-vendor-id-profile-id

Fetch device info by vendor id and vendor profile id
  • Loading branch information
vlasebian authored Sep 11, 2024
2 parents 8298a38 + f7f8cc6 commit f51ccc6
Show file tree
Hide file tree
Showing 18 changed files with 1,373 additions and 798 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For details about compatibility between different releases, see the **Commitment
- `ListFrequencyPlans` RPC has a new `gateways-only` flag.
- Option to pause application webhooks.
- Endpoint for claiming gateways using a qr code
- Update the GetTemplate endpoint in device repository to check for profile identifiers in the vendor index.

### Changed

Expand Down
49 changes: 47 additions & 2 deletions config/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4121,9 +4121,9 @@
"file": "store.go"
}
},
"error:pkg/devicerepository/store/bleve:multiple_identifiers": {
"error:pkg/devicerepository/store/bleve:missing_profile_identifiers": {
"translations": {
"en": "multiple identifiers found in the request. Use either EndDeviceVersionIdentifiers or EndDeviceProfileIdentifiers"
"en": "both vendor ID and vendor profile ID must be provided"
},
"description": {
"package": "pkg/devicerepository/store/bleve",
Expand All @@ -4139,6 +4139,15 @@
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:band_not_found_for_region": {
"translations": {
"en": "band not found for region `{region}`"
},
"description": {
"package": "pkg/devicerepository/store/remote",
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:brand_not_found": {
"translations": {
"en": "brand `{brand_id}` not found"
Expand All @@ -4148,6 +4157,15 @@
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:brand_with_vendor_id_not_found": {
"translations": {
"en": "brand with vendor ID `{vendor_id}` not found"
},
"description": {
"package": "pkg/devicerepository/store/remote",
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:firmware_version_not_found": {
"translations": {
"en": "firmware version `{firmware_version}` for model `{brand_id}/{model_id}` not found"
Expand All @@ -4157,6 +4175,15 @@
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:missing_profile_identifiers": {
"translations": {
"en": "both vendor ID and vendor profile ID must be provided"
},
"description": {
"package": "pkg/devicerepository/store/remote",
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:model_not_found": {
"translations": {
"en": "model `{brand_id}/{model_id}` not found"
Expand Down Expand Up @@ -4202,6 +4229,24 @@
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:no_template_identifiers": {
"translations": {
"en": "one of version_ids or end_device_profile_ids must be set"
},
"description": {
"package": "pkg/devicerepository/store/remote",
"file": "remote.go"
}
},
"error:pkg/devicerepository/store/remote:vendor_profile_id_not_found": {
"translations": {
"en": "vendor profile ID `{vendor_profile_id}` not found for vendor ID `{vendor_id}`"
},
"description": {
"package": "pkg/devicerepository/store/remote",
"file": "remote.go"
}
},
"error:pkg/devicerepository/store:regional_parameters_version": {
"translations": {
"en": "unknown Regional Parameters version `{phy_version}`"
Expand Down
2 changes: 1 addition & 1 deletion pkg/devicerepository/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (dr *DeviceRepository) GetTemplate(
if err := rights.RequireAuthenticated(ctx); err != nil {
return nil, err
}
return dr.store.GetTemplate(req, nil)
return dr.store.GetTemplate(req)
}

func getDecoder(
Expand Down
7 changes: 6 additions & 1 deletion pkg/devicerepository/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func (*mockStore) GetEndDeviceProfiles(
// GetTemplate retrieves an end device template for an end device definition.
func (s *mockStore) GetTemplate(
req *ttnpb.GetTemplateRequest,
_ *store.EndDeviceProfile,
) (*ttnpb.EndDeviceTemplate, error) {
s.lastVersionIDs = req.GetVersionIds()
profileIDs := req.GetEndDeviceProfileIds()
Expand All @@ -111,6 +110,12 @@ func (s *mockStore) GetTemplate(
return s.template, s.err
}

func (*mockStore) GetEndDeviceProfileIdentifiers(
_ store.GetEndDeviceProfileIdentifiersRequest,
) (*store.GetEndDeviceProfileIdentifiersResponse, error) {
return nil, nil //nolint:nilnil
}

// GetUplinkDecoder retrieves the codec for decoding uplink messages.
func (s *mockStore) GetUplinkDecoder(req store.GetCodecRequest) (*ttnpb.MessagePayloadDecoder, error) {
s.lastVersionIDs = req.GetVersionIds()
Expand Down
18 changes: 10 additions & 8 deletions pkg/devicerepository/store/bleve/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package bleve implements a Device Repository store with indexing capabilities
// using the bleve library.
package bleve

import (
Expand All @@ -29,12 +31,12 @@ import (
)

const (
// defaultTimeout is the timeout when trying to open the index. This is to avoid
// blocking on the index open call, which hangs indefinitely if the index is
// already in use by a different process.
// DefaultTimeout for opening the index. This is to avoid blocking on the index
// open call, which hangs indefinitely if the index is already in use by
// a different process.
defaultTimeout = 5 * time.Second

// cacheSize is the size of the cache for brands and models.
// CacheSize for brands and models.
cacheSize = 1024
)

Expand Down Expand Up @@ -78,11 +80,11 @@ func (c Config) NewStore(ctx context.Context) (store.Store, error) {

var errCannotOpenIndex = errors.DefineNotFound("cannot_open_index", "cannot open index")

func openIndex(ctx context.Context, path string) (bleve.Index, error) {
log.FromContext(ctx).WithField("path", path).Debug("Loading index")
index, err := bleve.OpenUsing(path, map[string]any{"read_only": true, "bolt_timeout": "60s"})
func openIndex(ctx context.Context, indexPath string) (bleve.Index, error) {
log.FromContext(ctx).WithField("path", indexPath).Debug("Loading index")
index, err := bleve.OpenUsing(indexPath, map[string]any{"read_only": true, "bolt_timeout": "60s"})
if err != nil {
return nil, errCannotOpenIndex.WithAttributes("path", path).WithCause(err)
return nil, errCannotOpenIndex.WithAttributes("path", indexPath).WithCause(err)
}
return index, nil
}
Loading

0 comments on commit f51ccc6

Please sign in to comment.