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

The following examples show how to use com.netflix.appinfo.InstanceInfo#getSecurePort() . 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: 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 3
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 4
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 5
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 6
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);
    }
}