public static AwsEndpoint instanceInfoToEndpoint(EurekaClientConfig clientConfig,
                                                     EurekaTransportConfig transportConfig,
                                                     InstanceInfo instanceInfo) {
        String zone = null;
        DataCenterInfo dataCenterInfo = instanceInfo.getDataCenterInfo();
        if (dataCenterInfo instanceof AmazonInfo) {
            zone = ((AmazonInfo) dataCenterInfo).get(AmazonInfo.MetaDataKey.availabilityZone);
        } else {
            zone = instanceInfo.getMetadata().get("zone");
        }

        String networkAddress;
        if (transportConfig.applicationsResolverUseIp()) {
            if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) {
                networkAddress = ((AmazonInfo) instanceInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.localIpv4);
            } else {
                networkAddress = instanceInfo.getIPAddr();
            }
        } else {
            networkAddress = instanceInfo.getHostName();
        }

        if (networkAddress == null) {  // final check
            logger.error("Cannot resolve InstanceInfo {} to a proper resolver endpoint, skipping", instanceInfo);
            return null;
        }

        return new AwsEndpoint(
                networkAddress,
                instanceInfo.getPort(),
                false,
                clientConfig.getEurekaServerURLContext(),
                clientConfig.getRegion(),
                zone
        );
    }
@Test
    public void testInstanceInfoToEndpoint() throws Exception {
        EurekaClientConfig clientConfig = mock(EurekaClientConfig.class);
        when(clientConfig.getEurekaServerURLContext()).thenReturn("/eureka");
        when(clientConfig.getRegion()).thenReturn("region");

        EurekaTransportConfig transportConfig = mock(EurekaTransportConfig.class);
        when(transportConfig.applicationsResolverUseIp()).thenReturn(false);

        AmazonInfo amazonInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone,
                "us-east-1c").build();
        InstanceInfo instanceWithAWSInfo = InstanceInfo.Builder.newBuilder().setAppName("appName")
                .setHostName("hostName").setPort(8080).setDataCenterInfo(amazonInfo).build();
        AwsEndpoint awsEndpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceWithAWSInfo);
        assertEquals("zone not equals.", "us-east-1c", awsEndpoint.getZone());

        MyDataCenterInfo myDataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
        InstanceInfo instanceWithMyDataInfo = InstanceInfo.Builder.newBuilder().setAppName("appName")
                .setHostName("hostName").setPort(8080).setDataCenterInfo(myDataCenterInfo)
                .add("zone", "us-east-1c").build();
        awsEndpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceWithMyDataInfo);
        assertEquals("zone not equals.", "us-east-1c", awsEndpoint.getZone());
    }