use of com.emc.storageos.coordinator.client.service.impl.DualInetAddress in project coprhd-controller by CoprHD.
the class DualInetAddressTest method testFromAddress.
@Test
public void testFromAddress() {
System.out.println("*** testFromAddress: Start");
for (String addr : normalizedInet4Addresses) {
try {
DualInetAddress d = DualInetAddress.fromAddress(addr);
Assert.assertTrue(addr.equals("0.0.0.0") && !d.hasInet4() || d.hasInet4());
Assert.assertTrue(!d.hasInet6());
Assert.assertTrue(addr.equals("0.0.0.0") && d.getInet4() == null || d.getInet4().equals(addr.toLowerCase()));
Assert.assertTrue(d.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
}
for (String addr : invalidInet4Addresses) {
try {
DualInetAddress d = DualInetAddress.fromAddress(addr);
Assert.assertTrue(addr == null && !d.hasInet4() && !d.hasInet6() && d.getInet4() == null && d.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(addr != null);
}
}
for (String addr : normalizedInet6Addresses) {
try {
DualInetAddress d = DualInetAddress.fromAddress(addr);
Assert.assertTrue(addr.equals("::0") && !d.hasInet6() || d.hasInet6());
Assert.assertTrue(!d.hasInet4());
Assert.assertTrue(addr.equals("::0") && d.getInet6() == null || d.getInet6().equals(addr.toLowerCase()));
Assert.assertTrue(d.getInet4() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
}
for (String addr : invalidInet6Addresses) {
try {
DualInetAddress d = DualInetAddress.fromAddress(addr);
// System.out.println(addr + " : " + d);
Assert.assertTrue(addr == null && !d.hasInet4() && !d.hasInet6() && d.getInet4() == null && d.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(addr != null);
}
}
for (int i = 0; i < 3; i++) {
String ip4 = normalizedInet4Addresses[i];
String ip6 = normalizedInet6Addresses[i];
try {
DualInetAddress d1 = DualInetAddress.fromAddresses(ip4, null);
DualInetAddress d2 = DualInetAddress.fromAddresses(null, ip6);
DualInetAddress d3 = DualInetAddress.fromAddresses(ip4, ip6);
Assert.assertTrue(ip4.equals("0.0.0.0") && !d1.hasInet4() || d1.hasInet4());
Assert.assertTrue(!d1.hasInet6());
Assert.assertTrue(ip4.equals("0.0.0.0") && d1.getInet4() == null || d1.getInet4().equals(ip4.toLowerCase()));
Assert.assertTrue(d1.getInet6() == null);
Assert.assertTrue(ip6.equals("::0") && !d2.hasInet6() || d2.hasInet6());
Assert.assertTrue(!d2.hasInet4());
Assert.assertTrue(ip6.equals("::0") && d2.getInet6() == null || d2.getInet6().equals(ip6.toLowerCase()));
Assert.assertTrue(d2.getInet4() == null);
Assert.assertTrue(ip4.equals("0.0.0.0") && !d3.hasInet4() || d3.hasInet4());
Assert.assertTrue(ip6.equals("::0") && !d3.hasInet6() || d3.hasInet6());
Assert.assertTrue(ip4.equals("0.0.0.0") && d3.getInet4() == null || d3.getInet4().equals(ip4.toLowerCase()));
Assert.assertTrue(ip6.equals("::0") && d3.getInet6() == null || d3.getInet6().equals(ip6.toLowerCase()));
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
}
for (int i = 0; i < 3; i++) {
String ip4 = invalidInet4Addresses[i];
String ip6 = normalizedInet6Addresses[i];
try {
DualInetAddress d1 = DualInetAddress.fromAddresses(ip4, null);
DualInetAddress d2 = DualInetAddress.fromAddresses(ip4, ip6);
// System.out.println(d1 + " " + d2);
Assert.assertTrue(ip4 == null && !d1.hasInet4() && !d2.hasInet4() && d1.getInet4() == null && d2.getInet4() == null && !d1.hasInet6() && d2.hasInet6() && d1.getInet6() == null && d2.getInet6().equals(ip6.toLowerCase()));
} catch (UnknownHostException e) {
Assert.assertTrue(ip4 != null);
}
}
for (int i = 0; i < 3; i++) {
String ip4 = normalizedInet4Addresses[i];
String ip6 = invalidInet6Addresses[i];
try {
DualInetAddress d1 = DualInetAddress.fromAddresses(null, ip6);
DualInetAddress d2 = DualInetAddress.fromAddresses(ip4, ip6);
// System.out.println(d1 + " " + d2);
Assert.assertTrue(ip6 == null && !d1.hasInet6() && !d2.hasInet6() && d1.getInet6() == null && d2.getInet6() == null && !d1.hasInet4() && d2.hasInet4() && d1.getInet4() == null && d2.getInet4().equals(ip4.toLowerCase()));
} catch (UnknownHostException e) {
Assert.assertTrue(ip4 != null);
}
}
System.out.println("*** testFromAddress: End");
}
use of com.emc.storageos.coordinator.client.service.impl.DualInetAddress in project coprhd-controller by CoprHD.
the class DualInetAddressTest method testFromHostname.
// This test requires internal accessible hosts and therefore is not viable for public/external builds of CoprHD, therefore disabling by default.
@Ignore
@Test
public void testFromHostname() {
System.out.println("*** testFromHostname: Start");
for (String addr : normalizedInet4Addresses) {
try {
DualInetAddress d = DualInetAddress.fromHostname(addr);
Assert.assertTrue(addr.equals("0.0.0.0") && !d.hasInet4() || d.hasInet4());
Assert.assertTrue(!d.hasInet6());
Assert.assertTrue(addr.equals("0.0.0.0") && d.getInet4() == null || d.getInet4().equals(addr.toLowerCase()));
Assert.assertTrue(d.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
}
for (String addr : invalidFrom4Addresses) {
try {
DualInetAddress d = DualInetAddress.fromHostname(addr);
Assert.assertTrue(addr == null && !d.hasInet4() && !d.hasInet6() && d.getInet4() == null && d.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(addr != null);
}
}
for (String addr : normalizedInet6Addresses) {
try {
DualInetAddress d = DualInetAddress.fromHostname(addr);
Assert.assertTrue(addr.equals("::0") && !d.hasInet6() || d.hasInet6());
Assert.assertTrue(!d.hasInet4());
Assert.assertTrue(addr.equals("::0") && d.getInet6() == null || d.getInet6().equals(addr.toLowerCase()));
Assert.assertTrue(d.getInet4() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
}
for (String addr : invalidFrom6Addresses) {
try {
DualInetAddress d = DualInetAddress.fromHostname(addr);
// System.out.println(addr + " : " + d);
Assert.assertTrue(addr == null && !d.hasInet4() && !d.hasInet6() && d.getInet4() == null && d.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(addr != null);
}
}
try {
DualInetAddress d = DualInetAddress.fromHostname("lglw7152.lss.emc.com");
// System.out.println(d);
Assert.assertTrue(d.hasInet4() && d.hasInet6());
Assert.assertTrue(d.getInet4().equals("10.247.97.152"));
Assert.assertTrue(d.getInet6().equals("2620:0:170:2842::7152"));
} catch (UnknownHostException e) {
System.err.println(e);
log.error("Caught UnknownHostException: ", e);
Assert.assertTrue(false);
}
try {
DualInetAddress d = DualInetAddress.fromHostname("bourne-52.lss.emc.com");
Assert.assertTrue(d.hasInet4() && !d.hasInet6());
Assert.assertTrue(d.getInet4().equals("10.10.191.52"));
Assert.assertTrue(d.getInet6() == null);
} catch (UnknownHostException e) {
System.err.println(e);
log.error("Caught UnknownHostException: ", e);
Assert.assertTrue(false);
}
try {
DualInetAddress d = DualInetAddress.fromHostname("nonexistant.lss.emc.com");
System.out.println(d);
Assert.assertTrue(false);
;
} catch (UnknownHostException e) {
Assert.assertTrue(true);
}
// Test empty ip strings
try {
DualInetAddress invalid_address1 = DualInetAddress.fromAddresses("", normalizedInet6Addresses[0]);
Assert.assertTrue(invalid_address1.getInet4() == null);
DualInetAddress invalid_address2 = DualInetAddress.fromAddresses(normalizedInet4Addresses[0], "");
Assert.assertTrue(invalid_address2.getInet6() == null);
DualInetAddress invalid_address3 = DualInetAddress.fromAddresses("", "");
Assert.assertTrue(invalid_address3.getInet4() == null);
Assert.assertTrue(invalid_address3.getInet6() == null);
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
System.out.println("*** testFromHostname: End");
}
use of com.emc.storageos.coordinator.client.service.impl.DualInetAddress in project coprhd-controller by CoprHD.
the class DualInetAddressTest method testConnectable.
// This test requires internal accessible hosts and therefore is not viable for public/external builds of CoprHD, therefore disabling by default.
@Ignore
@Test
public void testConnectable() {
System.out.println("*** testConnectable: Start");
try {
DualInetAddress c4 = DualInetAddress.fromAddresses(c_ip4, null);
DualInetAddress c6 = DualInetAddress.fromAddresses(null, c_ip6);
DualInetAddress cm = DualInetAddress.fromAddresses(c_ip4, c_ip6);
DualInetAddress s4 = DualInetAddress.fromAddresses(s_ip4, null);
DualInetAddress s6 = DualInetAddress.fromAddresses(null, s_ip6);
DualInetAddress sm = DualInetAddress.fromAddresses(s_ip4, s_ip6);
try {
DualInetAddress.ConnectableInetAddresses q44 = DualInetAddress.getConnectableAddresses(c4, s4);
DualInetAddress.ConnectableInetAddresses q66 = DualInetAddress.getConnectableAddresses(c6, s6);
DualInetAddress.ConnectableInetAddresses q4m = DualInetAddress.getConnectableAddresses(c4, sm);
DualInetAddress.ConnectableInetAddresses qm4 = DualInetAddress.getConnectableAddresses(cm, s4);
DualInetAddress.ConnectableInetAddresses qmm = DualInetAddress.getConnectableAddresses(cm, sm);
DualInetAddress.ConnectableInetAddresses q6m = DualInetAddress.getConnectableAddresses(c6, sm);
DualInetAddress.ConnectableInetAddresses qm6 = DualInetAddress.getConnectableAddresses(cm, s6);
Assert.assertEquals(q44.getClient(), c_ip4);
Assert.assertEquals(q66.getClient(), c_ip6);
Assert.assertEquals(q4m.getClient(), c_ip4);
Assert.assertEquals(qm4.getClient(), c_ip4);
Assert.assertEquals(qmm.getClient(), c_ip4);
Assert.assertEquals(q6m.getClient(), c_ip6);
Assert.assertEquals(qm6.getClient(), c_ip6);
Assert.assertEquals(q44.getServer(), s_ip4);
Assert.assertEquals(q66.getServer(), s_ip6);
Assert.assertEquals(q4m.getServer(), s_ip4);
Assert.assertEquals(qm4.getServer(), s_ip4);
Assert.assertEquals(qmm.getServer(), s_ip4);
Assert.assertEquals(q6m.getServer(), s_ip6);
Assert.assertEquals(qm6.getServer(), s_ip6);
} catch (Exception e) {
Assert.assertTrue(false);
}
try {
DualInetAddress.ConnectableInetAddresses q46 = DualInetAddress.getConnectableAddresses(c4, s6);
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(true);
}
try {
DualInetAddress.ConnectableInetAddresses q46 = DualInetAddress.getConnectableAddresses(c6, s4);
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(true);
}
try {
String s4m = c4.getConnectableAddress(s_host);
String smm = cm.getConnectableAddress(s_host);
String s6m = c6.getConnectableAddress(s_host);
Assert.assertEquals(s4m, s_ip4);
Assert.assertEquals(smm, s_ip4);
Assert.assertEquals(s6m, s_ip6);
} catch (Exception e) {
Assert.assertTrue(false);
}
} catch (UnknownHostException e) {
Assert.assertTrue(false);
}
System.out.println("*** testConnectable: End");
}
use of com.emc.storageos.coordinator.client.service.impl.DualInetAddress in project coprhd-controller by CoprHD.
the class BackupOps method checkBackupPropertyInfo.
private void checkBackupPropertyInfo(File propertyInfoFile, boolean isGeo) throws Exception {
RestoreManager manager = new RestoreManager();
CoordinatorClientImpl client = (CoordinatorClientImpl) coordinatorClient;
manager.setNodeCount(client.getNodeCount());
DualInetAddress addresses = coordinatorClient.getInetAddessLookupMap().getDualInetAddress();
String ipaddress4 = addresses.getInet4();
String ipaddress6 = addresses.getInet6();
manager.setIpAddress4(ipaddress4);
manager.setIpAddress6(ipaddress6);
manager.setEnableChangeVersion(false);
manager.checkBackupInfo(propertyInfoFile, isGeo);
}
use of com.emc.storageos.coordinator.client.service.impl.DualInetAddress in project coprhd-controller by CoprHD.
the class BackupOps method initHosts.
private synchronized void initHosts() {
CoordinatorClientInetAddressMap addressMap = getInetAddressLookupMap();
hosts = new TreeMap<>();
for (String nodeId : addressMap.getControllerNodeIPLookupMap().keySet()) {
try {
String ipAddr = addressMap.getConnectableInternalAddress(nodeId);
DualInetAddress inetAddress = DualInetAddress.fromAddress(ipAddr);
String host = normalizeDualInetAddress(inetAddress);
hosts.put(nodeId, host);
} catch (Exception ex) {
throw BackupException.fatals.failedToGetHost(nodeId, ex);
}
}
quorumSize = hosts.size() / 2 + 1;
}
Aggregations