Java Code Examples for com.netflix.appinfo.InstanceInfo#getPort()

The following examples show how to use com.netflix.appinfo.InstanceInfo#getPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmeriaEurekaClientTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static com.linecorp.armeria.internal.common.eureka.InstanceInfo convertInstanceInfo(
        InstanceInfo info) {
    final PortWrapper port = new PortWrapper(info.isPortEnabled(PortType.UNSECURE), info.getPort());
    final PortWrapper securePort = new PortWrapper(info.isPortEnabled(PortType.SECURE),
                                                   info.getSecurePort());

    return new com.linecorp.armeria.internal.common.eureka.InstanceInfo(
            info.getInstanceId(),
            info.getAppName(), info.getAppGroupName(), info.getHostName(),
            info.getIPAddr(),
            info.getVIPAddress(), info.getSecureVipAddress(), port,
            securePort,
            com.linecorp.armeria.internal.common.eureka.InstanceInfo.InstanceStatus
                    .toEnum(info.getStatus().name()), info.getHomePageUrl(),
            info.getStatusPageUrl(),
            info.getHealthCheckUrl(),
            info.getSecureHealthCheckUrl(),
            convertDataCenterInfo(info.getDataCenterInfo()),
            convertLeaseInfo(info.getLeaseInfo()),
            info.getMetadata());
}
 
Example 2
Source File: EurekaRegisterHandler.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private EndpointF convert2Endpoint(InstanceInfo instanceInfo) {
    EndpointF endpoint = null;
    if (instanceInfo == null) {
        return endpoint;
    }
    int istcp = instanceInfo.getMetadata().get("isTcp") == null ? 1 : Integer.parseInt(instanceInfo.getMetadata().get("isTcp"));
    int timeOut = instanceInfo.getMetadata().get("timeOut") == null ? 6000 : Integer.parseInt(instanceInfo.getMetadata().get("timeOut"));
    int grid = instanceInfo.getMetadata().get("grid") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("grid"));
    int qos = instanceInfo.getMetadata().get("qos") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("qos"));
    int weight = instanceInfo.getMetadata().get("weight") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("weight"));
    int weightType = instanceInfo.getMetadata().get("weightType") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("weightType"));
    endpoint = new EndpointF(instanceInfo.getIPAddr(), instanceInfo.getPort(), timeOut, istcp, grid, 0, 0, null, qos, 0, weight, weightType);
    return endpoint;
}
 
Example 3
Source File: EurekaUtils.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Construct base URL for specific InstanceInfo
 * @param instanceInfo Instance of service, for which we want to get an URL
 * @return URL to the instance
 */
public static final String getUrl(InstanceInfo instanceInfo) {
    if (instanceInfo.getSecurePort() == 0) {
        return "http://" + instanceInfo.getHostName() + ":" + instanceInfo.getPort();
    } else {
        return "https://" + instanceInfo.getHostName() + ":" + instanceInfo.getSecurePort();
    }
}
 
Example 4
Source File: APIDocRetrievalService.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a URL from the routing metadata 'apiml.routes.api-doc.serviceUrl' when 'apiml.apiInfo.swaggerUrl' is
 * not present
 *
 * @param instanceInfo the information about service instance
 * @return the URL of API doc endpoint
 * @deprecated Added to support services which were on-boarded before 'apiml.apiInfo.swaggerUrl' parameter was
 * introduced. It will be removed when all services will be using the new configuration style.
 */
@Deprecated
private String createApiDocUrlFromRouting(InstanceInfo instanceInfo, RoutedServices routes) {
    String scheme;
    int port;
    if (instanceInfo.isPortEnabled(InstanceInfo.PortType.SECURE)) {
        scheme = "https";
        port = instanceInfo.getSecurePort();
    } else {
        scheme = "http";
        port = instanceInfo.getPort();
    }

    String path = null;
    RoutedService route = routes.findServiceByGatewayUrl("api/v1/api-doc");
    if (route != null) {
        path = route.getServiceUrl();
    }

    if (path == null) {
        throw new ApiDocNotFoundException("No API Documentation defined for service " + instanceInfo.getAppName().toLowerCase() + " .");
    }

    UriComponents uri = UriComponentsBuilder
        .newInstance()
        .scheme(scheme)
        .host(instanceInfo.getHostName())
        .port(port)
        .path(path)
        .build();

    return uri.toUriString();
}
 
Example 5
Source File: ServiceInstance.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
public ServiceInstance(InstanceInfo instanceInfo) {
	this.appName = instanceInfo.getAppName();
	this.instanceId = instanceInfo.getInstanceId();
	this.hostName = instanceInfo.getHostName();
	this.ipAddr = instanceInfo.getIPAddr();
	this.vipAddress = instanceInfo.getVIPAddress();
	this.status = instanceInfo.getStatus().name();
	this.port = instanceInfo.getPort();
	this.healthCheckUrl = instanceInfo.getHealthCheckUrl();
	this.lastRenewalTime = new Date(instanceInfo.getLastDirtyTimestamp());
	this.nodeId = instanceInfo.getMetadata().get("nodeId");
}
 
Example 6
Source File: InstanceInfoMapper.java    From eureka-consul-adapter with MIT License 5 votes vote down vote up
private int getPort(InstanceInfo instanceInfo) {
    if (instanceInfo.isPortEnabled(SECURE)) {
        return instanceInfo.getSecurePort();
    } else {
        return instanceInfo.getPort();
    }
}
 
Example 7
Source File: ServiceGovenImpl.java    From hippo with Apache License 2.0 5 votes vote down vote up
@Override
public String getServiceAddress(String arg0) {
    try {
        InstanceInfo instanceInfo = getDiscoverClient().getNextServerFromEureka(arg0, false);
        if (instanceInfo != null) {
            return instanceInfo.getIPAddr() + ":" + instanceInfo.getPort();
        }
    } catch (Exception e) {
        LOGGER.error("can not get an instance of service from euraka server " + arg0, e);
        discoveryShutdown();
    }
    return "";
}
 
Example 8
Source File: DiscoveryEnabledServer.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public DiscoveryEnabledServer(final InstanceInfo instanceInfo, boolean useSecurePort, boolean useIpAddr) {
    super(useIpAddr ? instanceInfo.getIPAddr() : instanceInfo.getHostName(), instanceInfo.getPort());
	if(useSecurePort && instanceInfo.isPortEnabled(PortType.SECURE))
		super.setPort(instanceInfo.getSecurePort());
    this.instanceInfo = instanceInfo;
    this.serviceInfo = new MetaInfo() {
        @Override
        public String getAppName() {
            return instanceInfo.getAppName();
        }

        @Override
        public String getServerGroup() {
            return instanceInfo.getASGName();
        }

        @Override
        public String getServiceIdForDiscovery() {
            return instanceInfo.getVIPAddress();
        }

        @Override
        public String getInstanceId() {
            return instanceInfo.getId();
        }
    };
}
 
Example 9
Source File: RequestAttempt.java    From zuul with Apache License 2.0 5 votes vote down vote up
public RequestAttempt(int attemptNumber, InstanceInfo server, String targetVip, String chosenWarmupLB, int status, String error, String exceptionType,
                      int readTimeout, int connectTimeout, int maxRetries)
{
    if (attemptNumber < 1) {
        throw new IllegalArgumentException("Attempt number must be greater than 0! - " + attemptNumber);
    }
    this.attempt = attemptNumber;
    this.vip = targetVip;

    if (server != null) {
        this.app = server.getAppName().toLowerCase();
        this.asg = server.getASGName();
        this.instanceId = server.getInstanceId();
        this.host = server.getHostName();
        this.port = server.getPort();

        // If targetVip is null, then try to use the actual server's vip.
        if (targetVip == null) {
            this.vip = server.getVIPAddress();
        }

        if (server.getDataCenterInfo() instanceof AmazonInfo) {
            this.availabilityZone = ((AmazonInfo) server.getDataCenterInfo()).getMetadata().get("availability-zone");

            // HACK - get region by just removing the last char from zone.
            String az = getAvailabilityZone();
            if (az != null && az.length() > 0) {
                this.region = az.substring(0, az.length() - 1);
            }
        }
    }
    
    this.status = status;
    this.error = error;
    this.exceptionType = exceptionType;
    this.readTimeout = readTimeout;
    this.connectTimeout = connectTimeout;
    this.maxRetries = maxRetries;
}
 
Example 10
Source File: EurekaRegistry.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
public String getRealServerHost(String serviceId){
	InstanceInfo serverInfo = eurekaClient.getNextServerFromEureka(serviceId, false);
	String realServerName = serverInfo.getIPAddr() + ":" + serverInfo.getPort();
	return realServerName;
}
 
Example 11
Source File: RequestAttempt.java    From zuul with Apache License 2.0 4 votes vote down vote up
public RequestAttempt(final Server server, final IClientConfig clientConfig, int attemptNumber, int readTimeout) {
    this.status = -1;
    this.attempt = attemptNumber;
    this.readTimeout = readTimeout;

    if (server != null) {
        this.host = server.getHost();
        this.port = server.getPort();
        this.availabilityZone = server.getZone();

        if (server instanceof DiscoveryEnabledServer) {
            InstanceInfo instanceInfo = ((DiscoveryEnabledServer) server).getInstanceInfo();
            this.app = instanceInfo.getAppName().toLowerCase();
            this.asg = instanceInfo.getASGName();
            this.instanceId = instanceInfo.getInstanceId();
            this.host = instanceInfo.getHostName();
            this.port = instanceInfo.getPort();

            if (server.getPort() == instanceInfo.getSecurePort()) {
                this.vip = instanceInfo.getSecureVipAddress();
            }
            else {
                this.vip = instanceInfo.getVIPAddress();
            }
            if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) {
                this.availabilityZone = ((AmazonInfo) instanceInfo.getDataCenterInfo()).getMetadata().get("availability-zone");
            }
        }
        else {
            final Server.MetaInfo metaInfo = server.getMetaInfo();
            if (metaInfo != null) {
                this.asg = metaInfo.getServerGroup();
                this.vip = metaInfo.getServiceIdForDiscovery();
                this.instanceId = metaInfo.getInstanceId();
            }
        }
        // HACK - get region by just removing the last char from zone.
        if (availabilityZone != null && availabilityZone.length() > 0) {
            region = availabilityZone.substring(0, availabilityZone.length() - 1);
        }
    }

    if (clientConfig != null) {
        this.connectTimeout = clientConfig.get(IClientConfigKey.Keys.ConnectTimeout);
    }
}