Search in sources :

Example 1 with DRNatCheckResponse

use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method checkIfBehindNat.

/**
 * Check Data Replication If Behind NAT
 *
 * @param checkParam
 * @param clientIp
 * @brief Check if behind NAT
 * @return DRNatCheckResponse
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
@Path("/natcheck")
@ExcludeLicenseCheck
public DRNatCheckResponse checkIfBehindNat(DRNatCheckParam checkParam, @HeaderParam("X-Forwarded-For") String clientIp) {
    if (checkParam == null) {
        log.error("checkParam is null, X-Forwarded-For is {}", clientIp);
        throw APIException.internalServerErrors.invalidNatCheckCall("(null)", clientIp);
    }
    String ipv4Str = checkParam.getIPv4Address();
    String ipv6Str = checkParam.getIPv6Address();
    log.info(String.format("Performing NAT check, client address connecting to VIP: %s. Client reports its IPv4 = %s, IPv6 = %s", clientIp, ipv4Str, ipv6Str));
    boolean isBehindNat = false;
    try {
        isBehindNat = sysUtils.checkIfBehindNat(ipv4Str, ipv6Str, clientIp);
    } catch (Exception e) {
        log.error("Fail to check NAT {}", e);
        throw APIException.internalServerErrors.invalidNatCheckCall(e.getMessage(), clientIp);
    }
    DRNatCheckResponse resp = new DRNatCheckResponse();
    resp.setSeenIp(clientIp);
    resp.setBehindNAT(isBehindNat);
    return resp;
}
Also used : DRNatCheckResponse(com.emc.storageos.model.dr.DRNatCheckResponse) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) UnknownHostException(java.net.UnknownHostException) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ExcludeLicenseCheck(com.emc.storageos.security.authorization.ExcludeLicenseCheck) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with DRNatCheckResponse

use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testCheckIfBehindNat_NotBehindNAT.

@Test
public void testCheckIfBehindNat_NotBehindNAT() {
    natCheckParam.setIPv4Address("10.247.101.110");
    DRNatCheckResponse response = drService.checkIfBehindNat(natCheckParam, "10.247.101.110");
    assertEquals(false, response.isBehindNAT());
}
Also used : DRNatCheckResponse(com.emc.storageos.model.dr.DRNatCheckResponse) Test(org.junit.Test)

Example 3 with DRNatCheckResponse

use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method mockViPRCoreClient.

protected ViPRCoreClient mockViPRCoreClient(final String uuid) {
    class MockViPRCoreClient extends ViPRCoreClient {

        @Override
        public com.emc.vipr.client.core.Site site() {
            com.emc.vipr.client.core.Site site = mock(com.emc.vipr.client.core.Site.class);
            SiteConfigRestRep config = new SiteConfigRestRep();
            config.setUuid(uuid);
            config.setHostIPv4AddressMap(new HashMap<String, String>());
            config.setHostIPv6AddressMap(new HashMap<String, String>());
            doReturn(config).when(site).getStandbyConfig();
            doReturn(null).when(site).syncSite(anyString(), any(SiteConfigParam.class));
            doReturn(new DRNatCheckResponse()).when(site).checkIfBehindNat(any(DRNatCheckParam.class));
            return site;
        }
    }
    return new MockViPRCoreClient();
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) DRNatCheckResponse(com.emc.storageos.model.dr.DRNatCheckResponse) DRNatCheckParam(com.emc.storageos.model.dr.DRNatCheckParam) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep) Matchers.anyString(org.mockito.Matchers.anyString) SiteConfigParam(com.emc.storageos.model.dr.SiteConfigParam)

Example 4 with DRNatCheckResponse

use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testCheckIfBehindNat_IsBehindNAT.

@Test
public void testCheckIfBehindNat_IsBehindNAT() {
    natCheckParam.setIPv4Address("10.247.101.111");
    DRNatCheckResponse response = drService.checkIfBehindNat(natCheckParam, "10.247.101.110");
    assertEquals(true, response.isBehindNAT());
}
Also used : DRNatCheckResponse(com.emc.storageos.model.dr.DRNatCheckResponse) Test(org.junit.Test)

Example 5 with DRNatCheckResponse

use of com.emc.storageos.model.dr.DRNatCheckResponse in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method checkNATForAttachStandby.

private void checkNATForAttachStandby(ViPRCoreClient viprCoreClient) {
    DualInetAddress inetAddress = coordinator.getInetAddessLookupMap().getDualInetAddress();
    String ipv4 = inetAddress.getInet4();
    String ipv6 = inetAddress.getInet6();
    log.info("Got local node's IP addresses, IPv4 = {}, IPv6 = {}", ipv4, ipv6);
    DRNatCheckParam checkParam = new DRNatCheckParam();
    checkParam.setIPv4Address(ipv4);
    checkParam.setIPv6Address(ipv6);
    DRNatCheckResponse resp = viprCoreClient.site().checkIfBehindNat(checkParam);
    if (resp.isBehindNAT()) {
        throw APIException.internalServerErrors.addStandbyPrecheckFailed(String.format("The remote site sees this node's IP as %s, which is different from the local addresses: %s or %s, it may be behind a NAT.", resp.getSeenIp(), ipv4, ipv6));
    }
}
Also used : DRNatCheckResponse(com.emc.storageos.model.dr.DRNatCheckResponse) DRNatCheckParam(com.emc.storageos.model.dr.DRNatCheckParam) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress)

Aggregations

DRNatCheckResponse (com.emc.storageos.model.dr.DRNatCheckResponse)5 DRNatCheckParam (com.emc.storageos.model.dr.DRNatCheckParam)2 Test (org.junit.Test)2 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)1 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)1 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)1 SiteConfigParam (com.emc.storageos.model.dr.SiteConfigParam)1 SiteConfigRestRep (com.emc.storageos.model.dr.SiteConfigRestRep)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ExcludeLicenseCheck (com.emc.storageos.security.authorization.ExcludeLicenseCheck)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)1 UnknownHostException (java.net.UnknownHostException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Matchers.anyString (org.mockito.Matchers.anyString)1