Skip to content

Commit

Permalink
Add a check to see if two hosts are the same #60
Browse files Browse the repository at this point in the history
  • Loading branch information
apertome committed Sep 21, 2018
1 parent f15029a commit d7c7c4a
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions api/pwacache-dedupe.js
Expand Up @@ -8,6 +8,8 @@ const winston = require('winston');
const async = require('async');
const request = require('request');
const assert = require('assert');
const urlLib = require('url');
//const { URL } = require('url');

//mine
const config = require('./config');
Expand All @@ -30,7 +32,8 @@ console.warn("CONFIG", JSON.stringify(config.datasource, null, 4));
var hostsToQuery = [
{
//"host-name": "psb.hpc.utfsm.cl",
"client-uuid": "3A7CFE34-FB6D-11E7-928E-D0860605CAE2",
//"client-uuid": "3A7CFE34-FB6D-11E7-928E-D0860605CAE2", //CL example
"client-uuid": "58daadb8-4382-489e-ba91-39e1784ba940",

}];

Expand Down Expand Up @@ -88,7 +91,10 @@ function run() {
console.error("HOSTS FROM DB - ", hosts.length, hosts);
for(var j in hosts) {
var host = hosts[j];
console.log("host addresses", host.addresses);
if ( sameHost( host, host ) ) { // TODO: fix 2nd argument
console.log("SAME HOST!!!");
}
//console.log("host addresses", host.addresses);

}

Expand All @@ -99,6 +105,36 @@ function run() {
});
}

// check to see if two records belong to the same host
function sameHost( host1, host2 ) {
const uniqueFields = {
"ls": ["client-uuid", "host-name"],
"db": ["uuid", "addresses"]
};

var host1Addresses;
if ( isLsHost( host1 ) ) {
host1Addresses = host1["host-name"];
} else {
host1Addresses = host1["addresses"].map( address => address.address );
}
console.log("host1Addresses", host1Addresses);



}

// check whether we are looking at an LS or a PWA DB host record
function isLsHost( host ) {
// the LS uses "host-name" for the hostname field, while
// the PWA db uses "hostname"
if ( "host-name" in host ) {
return true;
}
return false;

}

function getHostsFromLS( hostsArr, hostsToQuery, ls, lsid, cb ) {
//console.warn("Getting host from LS ", lsid, ls);
var ah_url = ls.url;
Expand All @@ -125,6 +161,10 @@ function getHostsFromLS( hostsArr, hostsToQuery, ls, lsid, cb ) {
//console.warn("host result", body);
var objKey = key + "-" + val;
if ( body.length > 0 ) {
var lsBaseUrl = url;
lsBaseUrl= lsBaseUrl.match(/^http.?:\/\/[^\/]+/) + '/';
//console.error("lsBaseUrl", lsBaseUrl);
formatLsHostRecords( body, lsBaseUrl );
lsHostArr = lsHostArr.concat( body );
console.log("lsHostArr.length", lsHostArr.length);

Expand All @@ -136,9 +176,17 @@ function getHostsFromLS( hostsArr, hostsToQuery, ls, lsid, cb ) {
if(err) logger.error(err);
console.log("lsHostArr after finishing loplp", lsHostArr.length);
if(cb) cb();

});

}

function formatLsHostRecords( hosts, ls_url ) {
for(var i in hosts ) {
var host = hosts[i];
host._url_full = ls_url + host.uri;
};
return hosts;


}
Expand Down

0 comments on commit d7c7c4a

Please sign in to comment.