@@ -12,7 +12,7 @@ import AssociateModal from 'components/AssociateModal';
1212import ErrorDetail from 'components/ErrorDetail' ;
1313import AlertModal from 'components/AlertModal' ;
1414import useToast , { AlertVariant } from 'hooks/useToast' ;
15- import { getQSConfig , parseQueryString , mergeParams } from 'util/qs' ;
15+ import { getQSConfig , parseQueryString } from 'util/qs' ;
1616import { useLocation , useParams } from 'react-router-dom' ;
1717import useRequest , { useDismissableError } from 'hooks/useRequest' ;
1818import DataListToolbar from 'components/DataListToolbar' ;
@@ -106,72 +106,48 @@ function InstancePeerList({ setBreadcrumb }) {
106106 const { selected, isAllSelected, handleSelect, clearSelected, selectAll } =
107107 useSelected ( peers ) ;
108108
109- const fetchInstancesToAssociate = useCallback (
109+ const fetchPeersToAssociate = useCallback (
110110 async ( params ) => {
111111 const address_list = [ ] ;
112112
113- const instances = await InstancesAPI . read (
114- mergeParams ( params , {
115- ...{ not__node_type : [ 'control' , 'hybrid' ] } ,
116- } )
117- ) ;
118- const receptors = ( await ReceptorAPI . read ( ) ) . data . results ;
113+ // do not show this instance or instances that are already peered
114+ // to this instance (reverse_peers)
115+ const not_instances = instance . reverse_peers ;
116+ not_instances . push ( instance . id ) ;
119117
120- // get instance ids of the current peered receptor ids
121- const already_peered_instance_ids = [ ] ;
122- for ( let h = 0 ; h < instance . peers . length ; h ++ ) {
123- const matched = receptors . filter ( ( obj ) => obj . id === instance . peers [ h ] ) ;
124- matched . forEach ( ( element ) => {
125- already_peered_instance_ids . push ( element . instance ) ;
126- } ) ;
118+ params . not__instance = not_instances ;
119+ params . is_internal = false ;
120+ // do not show the current peers
121+ if ( instance . peers . length > 0 ) {
122+ params . not__id__in = instance . peers . join ( ',' ) ;
127123 }
128124
129- for ( let q = 0 ; q < receptors . length ; q ++ ) {
130- const receptor = receptors [ q ] ;
131-
132- if ( already_peered_instance_ids . includes ( receptor . instance ) ) {
133- // ignore reverse peers
134- continue ;
135- }
125+ const receptoraddresses = await ReceptorAPI . read ( params ) ;
136126
137- if ( instance . peers . includes ( receptor . id ) ) {
138- // no links to existing links
139- continue ;
140- }
141-
142- if ( instance . id === receptor . instance ) {
143- // no links to thy self
144- continue ;
145- }
127+ // retrieve the instances that are associated with those receptor addresses
128+ const instance_ids = receptoraddresses . data . results . map (
129+ ( obj ) => obj . instance
130+ ) ;
131+ const instance_ids_str = instance_ids . join ( ',' ) ;
132+ const instances = await InstancesAPI . read ( { id__in : instance_ids_str } ) ;
146133
147- if ( instance . managed ) {
148- // no managed nodes
149- continue ;
150- }
134+ for ( let q = 0 ; q < receptoraddresses . data . results . length ; q ++ ) {
135+ const receptor = receptoraddresses . data . results [ q ] ;
151136
152137 const host = instances . data . results . filter (
153138 ( obj ) => obj . id === receptor . instance
154139 ) [ 0 ] ;
155140
156- if ( host === undefined ) {
157- // no hosts
158- continue ;
159- }
160-
161- if ( receptor . is_internal ) {
162- continue ;
163- }
164-
165141 const copy = receptor ;
166142 copy . hostname = host . hostname ;
167143 copy . node_type = host . node_type ;
168144 copy . canonical = copy . canonical . toString ( ) ;
169145 address_list . push ( copy ) ;
170146 }
171147
172- instances . data . results = address_list ;
148+ receptoraddresses . data . results = address_list ;
173149
174- return instances ;
150+ return receptoraddresses ;
175151 } ,
176152 [ instance ]
177153 ) ;
@@ -191,7 +167,7 @@ function InstancePeerList({ setBreadcrumb }) {
191167 fetchPeers ( ) ;
192168 addToast ( {
193169 id : instancesPeerToAssociate ,
194- title : t `Please be sure to run the install bundle for the selected instance(s) again in order to see changes take effect.` ,
170+ title : t `Please be sure to run the install bundle for ${ instance . hostname } again in order to see changes take effect.` ,
195171 variant : AlertVariant . success ,
196172 hasTimeout : true ,
197173 } ) ;
@@ -315,13 +291,13 @@ function InstancePeerList({ setBreadcrumb }) {
315291 { isModalOpen && (
316292 < AssociateModal
317293 header = { t `Instances` }
318- fetchRequest = { fetchInstancesToAssociate }
294+ fetchRequest = { fetchPeersToAssociate }
319295 isModalOpen = { isModalOpen }
320296 onAssociate = { handlePeerAssociate }
321297 onClose = { ( ) => setIsModalOpen ( false ) }
322298 title = { t `Select Peer Addresses` }
323299 optionsRequest = { readInstancesOptions }
324- displayKey = "hostname "
300+ displayKey = "address "
325301 columns = { [
326302 { key : 'hostname' , name : t `Name` } ,
327303 { key : 'address' , name : t `Address` } ,
0 commit comments