private DiscoveryEnabledServer createServer(String host, int port, String zone) { AmazonInfo amazonInfo = AmazonInfo.Builder.newBuilder() .addMetadata(AmazonInfo.MetaDataKey.availabilityZone, zone) .build(); Builder builder = InstanceInfo.Builder.newBuilder(); InstanceInfo info = builder .setAppName("l10nservicegeneral") .setDataCenterInfo(amazonInfo) .setHostName(host) .setPort(port) .build(); DiscoveryEnabledServer server = new DiscoveryEnabledServer(info, false); server.setZone(zone); return server; }
// useInstanceId to false to generate older InstanceInfo types that does not use instanceId field // for instance id. private InstanceInfo generateInstanceInfo( int appIndex, int appInstanceId, boolean useInstanceId) { String appName = appNames[appIndex]; String hostName = "instance" + appInstanceId + '.' + appName + ".com"; String publicIp = "20.0." + appIndex + '.' + appInstanceId; String privateIp = "192.168." + appIndex + '.' + appInstanceId; String instanceId = String.format("i-%04d%04d", appIndex, appInstanceId); if (taggedId) { instanceId = instanceId + '_' + appName; } AmazonInfo dataCenterInfo = AmazonInfo.Builder.newBuilder() .addMetadata(MetaDataKey.accountId, "testAccountId") .addMetadata(MetaDataKey.amiId, String.format("ami-%04d%04d", appIndex, appInstanceId)) .addMetadata(MetaDataKey.availabilityZone, zone) .addMetadata(MetaDataKey.instanceId, instanceId) .addMetadata(MetaDataKey.instanceType, "m2.xlarge") .addMetadata(MetaDataKey.localIpv4, privateIp) .addMetadata(MetaDataKey.publicHostname, hostName) .addMetadata(MetaDataKey.publicIpv4, publicIp) .build(); String unsecureURL = "http://" + hostName + ":8080"; String secureURL = "https://" + hostName + ":8081"; long now = System.currentTimeMillis(); LeaseInfo leaseInfo = LeaseInfo.Builder.newBuilder() .setDurationInSecs(3 * RENEW_INTERVAL) .setRenewalIntervalInSecs(RENEW_INTERVAL) .setServiceUpTimestamp(now - RENEW_INTERVAL) .setRegistrationTimestamp(now) .setEvictionTimestamp(now + 3 * RENEW_INTERVAL) .setRenewalTimestamp(now + RENEW_INTERVAL) .build(); Builder builder = useInstanceId ? InstanceInfo.Builder.newBuilder().setInstanceId(instanceId) : InstanceInfo.Builder.newBuilder(); builder .setActionType(ActionType.ADDED) .setAppGroupName(appName + "Group") .setAppName(appName) .setHostName(hostName) .setIPAddr(publicIp) .setPort(8080) .setSecurePort(8081) .enablePort(PortType.SECURE, true) .setHealthCheckUrls( "/healthcheck", unsecureURL + "/healthcheck", secureURL + "/healthcheck") .setHomePageUrl("/homepage", unsecureURL + "/homepage") .setStatusPageUrl("/status", unsecureURL + "/status") .setLeaseInfo(leaseInfo) .setStatus(InstanceStatus.UP) .setVIPAddress(hostName + ":8080") .setSecureVIPAddress(hostName + ":8081") .setDataCenterInfo(dataCenterInfo) .setLastUpdatedTimestamp(System.currentTimeMillis() - 100) .setLastDirtyTimestamp(System.currentTimeMillis() - 100) .setIsCoordinatingDiscoveryServer(true) .enablePort(PortType.UNSECURE, true); if (includeAsg) { builder.setASGName(appName + "ASG"); } if (withMetaData) { builder.add("appKey" + appIndex, Integer.toString(appInstanceId)); } return builder.build(); }