Notifications

104 views

Description

On domain separated instance, MID Selector sometimes returns sys_id of MID Servers that are not in the same domain as the caller, sometimes it leads to the error "Invalid mid server ID was found by CloudMidSelectionApi "

Ex: User calling MID Selector logic is in Domain A and the logic returns sys_id of MID Server in Domain B.

Steps to Reproduce

Example 1:

  1. Configure Domain Separation
  2. Take 3 users, Admin in global domain, acme user in acme domain and cisco in Cisco domain
  3. Create 2 MID servers in global domain, status Up and Validated
  4. Create 2 MID servers in acme domain, status Up and Validated
  5. Create 2 MID servers in cisco domain, status Up and Validated
  6. Run following script backgoudn as each domain user
var app = null; 
var capabilities = null;
var context = null;
var midSelector = new SNC.MidSelector();
var midservers = midSelector.select(null, null, null, null);
for(var i=0; i< midservers.length; i++)
gs.log(midservers[i]);

var gr = new GlideRecord('ecc_agent');
gr.query();
gs.log(gr.getRowCount());

Result and Expectation:
Run as Admin User:
Prints 6 sys ID of MID servers and 6 row count (expected)

Run as Acme user:
Prints 6 sys ID fo MID servers and 4 row count (expected 4 sys IDs and 4 row count)

Run as Cisco User
Prints 6 sys ID fo MID servers and 4 row count (expected 4 sys IDs and 4 row count)

 

Example 2

  1. Configure Domain Separation
  2. Install and configure two MID Servers, each in a different domain
  3. Configure MID Server user to be in the same domain as one of the above mid servers
  4. Create a scheduled script execution and execute the following script as the above MID Server user:
var app = '';
var capabilities = [{"capability":"Cloud Management"},{"capability":"AWS","value":"us-west-1"}];
var context = '"{\"location_name\":\"us-west-1\",\"capi_impl_name\":\"AWS Compute API\",\"endpoint_url\":null,\"correlation_id\":\"dce44f3cdb0fa704d49e9532ca9619e3\",\"capi_method_name\":\"ListHardwareTypes\",\"capi_interface_name\":\"Compute Interface\",\"targets\":null,\"service_account_id\":\"598329518172\",\"capi_method_parameters\":{\"Project\":\"$(CloudCredential.project_name)\",\"Endpoint\":\"$(CloudCredential.URL)\",\"Identity\":\"$(CloudCredential.access_key)\",\"Credentials\":\"$(CloudCredential.secret_key)\",\"CloudOperation\":\"ListHardwareTypes\",\"Provider\":\"aws-ec2\",\"AccountAliasName\":\"$(CloudCredential.Alias)\"}}"';

var midSelector = new SNC.MidSelector();
var midId = midSelector.selectMid(app, null, capabilities, context);
gs.log(midId);

if (midId){
var agent = new GlideRecord('ecc_agent');
agent.get(midId);
gs.log('Name: ' + agent.name + ', status: ' + agent.status + ', started: ' + agent.started + ', sys_id: ' + agent.sys_id);
}

var mid = new Packages.com.snc.mid.util.midselector.MidServersConfig().getMidServerBySysId(midId);
gs.log(mid);

Verify in syslog that intermittently, sysid of MID Server in a different domain is returned

Workaround

This problem has been fixed. If you are able to upgrade, review the Fixed In or Intended Fix Version fields to determine whether any versions have a planned or permanent fix and till that time use the below workaround.

When calling midSelector.SelectMid(...), replace with following,

var midSysIds = [];
var validMidSysIds = [];
var validMid = '';
midSysIds = midSelector.select(app, null, capabilities, context);
for( var midCount=0; midCount< midSysIds.length; midCount++) {
var midGr = new GlideRecord("ecc_agent");
midGr.get(midSysIds[midCount]);
if(midGr.isValid()) { 
validMidSysIds.push(midSysIds[midCount]); //you can return here from first valid MID to save some on performance. 

}

if(validMidSysIds.length != 0) {
var randomMid = Math.floor((Math.random() * validMidSysIds.length));
validMid = validMidSysIds[randomMid];
} else
gs.log('SNCTEST no Valid MID server found');

// Now we have everything set up - call the mid selector API to select one mid
return validMid;

 

Note: Workaround has very little performance overhead. 


Related Problem: PRB1323398

Seen In

There is no data to report.

Fixed In

London Patch 7
Madrid Patch 2
New York

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2019-08-22 10:36:16
Published:2019-05-27