@@ -20,11 +20,11 @@ const (
20
20
// ServiceDiscoveryApi handles the AWS Cloud Map API request and response processing logic, and converts results to
21
21
// internal data structures. It manages all interactions with the AWS SDK.
22
22
type ServiceDiscoveryApi interface {
23
- // ListNamespaces returns a list of all namespaces.
24
- ListNamespaces (ctx context.Context ) (namespaces [ ]* model.Namespace , err error )
23
+ // GetNamespaceMap returns a map of all namespaces in the Cloud Map account indexed by namespace name .
24
+ GetNamespaceMap (ctx context.Context ) (namespaces map [ string ]* model.Namespace , err error )
25
25
26
- // ListServices returns a list of services for a given namespace.
27
- ListServices (ctx context.Context , namespaceId string ) (services [] * model. Resource , err error )
26
+ // GetServiceIdMap returns a map of all service IDs for a given namespace indexed by service name .
27
+ GetServiceIdMap (ctx context.Context , namespaceId string ) (serviceIdMap map [ string ] string , err error )
28
28
29
29
// DiscoverInstances returns a list of service instances registered to a given service.
30
30
DiscoverInstances (ctx context.Context , nsName string , svcName string ) (insts []types.HttpInstanceSummary , err error )
@@ -64,52 +64,53 @@ func NewServiceDiscoveryApiFromConfig(cfg *aws.Config) ServiceDiscoveryApi {
64
64
}
65
65
}
66
66
67
- func (sdApi * serviceDiscoveryApi ) ListNamespaces (ctx context.Context ) (namespaces [ ]* model.Namespace , err error ) {
68
- pages := sd . NewListNamespacesPaginator ( sdApi . awsFacade , & sd. ListNamespacesInput {} )
67
+ func (sdApi * serviceDiscoveryApi ) GetNamespaceMap (ctx context.Context ) (map [ string ]* model.Namespace , error ) {
68
+ namespaceMap := make ( map [ string ] * model. Namespace )
69
69
70
+ pages := sd .NewListNamespacesPaginator (sdApi .awsFacade , & sd.ListNamespacesInput {})
70
71
for pages .HasMorePages () {
71
72
output , err := pages .NextPage (ctx )
72
73
if err != nil {
73
- return namespaces , err
74
+ return nil , err
74
75
}
75
76
76
77
for _ , ns := range output .Namespaces {
77
- if namespaceType := model .ConvertNamespaceType (ns .Type ); ! namespaceType .IsUnsupported () {
78
- namespaces = append (namespaces , & model.Namespace {
79
- Id : aws .ToString (ns .Id ),
80
- Name : aws .ToString (ns .Name ),
81
- Type : namespaceType ,
82
- })
78
+ namespaceType := model .ConvertNamespaceType (ns .Type )
79
+ if namespaceType .IsUnsupported () {
80
+ continue
81
+ }
82
+ namespaceMap [aws .ToString (ns .Name )] = & model.Namespace {
83
+ Id : aws .ToString (ns .Id ),
84
+ Name : aws .ToString (ns .Name ),
85
+ Type : namespaceType ,
83
86
}
84
87
}
85
88
}
86
89
87
- return namespaces , nil
90
+ return namespaceMap , nil
88
91
}
89
92
90
- func (sdApi * serviceDiscoveryApi ) ListServices (ctx context.Context , nsId string ) (svcs []* model.Resource , err error ) {
93
+ func (sdApi * serviceDiscoveryApi ) GetServiceIdMap (ctx context.Context , nsId string ) (map [string ]string , error ) {
94
+ serviceIdMap := make (map [string ]string )
95
+
91
96
filter := types.ServiceFilter {
92
97
Name : types .ServiceFilterNameNamespaceId ,
93
98
Values : []string {nsId },
94
99
}
95
100
96
101
pages := sd .NewListServicesPaginator (sdApi .awsFacade , & sd.ListServicesInput {Filters : []types.ServiceFilter {filter }})
97
-
98
102
for pages .HasMorePages () {
99
103
output , err := pages .NextPage (ctx )
100
104
if err != nil {
101
- return svcs , err
105
+ return nil , err
102
106
}
103
107
104
108
for _ , svc := range output .Services {
105
- svcs = append (svcs , & model.Resource {
106
- Id : aws .ToString (svc .Id ),
107
- Name : aws .ToString (svc .Name ),
108
- })
109
+ serviceIdMap [aws .ToString (svc .Name )] = aws .ToString (svc .Id )
109
110
}
110
111
}
111
112
112
- return svcs , nil
113
+ return serviceIdMap , nil
113
114
}
114
115
115
116
func (sdApi * serviceDiscoveryApi ) DiscoverInstances (ctx context.Context , nsName string , svcName string ) (insts []types.HttpInstanceSummary , err error ) {
@@ -127,8 +128,8 @@ func (sdApi *serviceDiscoveryApi) DiscoverInstances(ctx context.Context, nsName
127
128
return out .Instances , nil
128
129
}
129
130
130
- func (sdApi * serviceDiscoveryApi ) ListOperations (ctx context.Context , opFilters []types.OperationFilter ) (opStatusMap map [string ]types.OperationStatus , err error ) {
131
- opStatusMap = make (map [string ]types.OperationStatus )
131
+ func (sdApi * serviceDiscoveryApi ) ListOperations (ctx context.Context , opFilters []types.OperationFilter ) (map [string ]types.OperationStatus , error ) {
132
+ opStatusMap : = make (map [string ]types.OperationStatus )
132
133
133
134
pages := sd .NewListOperationsPaginator (sdApi .awsFacade , & sd.ListOperationsInput {
134
135
Filters : opFilters ,
@@ -190,7 +191,7 @@ func (sdApi *serviceDiscoveryApi) CreateService(ctx context.Context, namespace m
190
191
}
191
192
192
193
svcId = aws .ToString (output .Service .Id )
193
- sdApi .log .Info ("service created" , "svcId " , svcId )
194
+ sdApi .log .Info ("service created" , "namespace" , namespace . Name , "name" , svcName , "id " , svcId )
194
195
return svcId , nil
195
196
}
196
197
0 commit comments