Exemple #1
0
 /**
  * Handles EIP binding process in AWS Cloud.
  *
  * @throws InterruptedException
  */
 private void handleEIPBinding() throws InterruptedException {
   int retries = serverConfig.getEIPBindRebindRetries();
   // Bind to EIP if needed
   for (int i = 0; i < retries; i++) {
     try {
       if (isEIPBound()) {
         break;
       } else {
         bindEIP();
       }
     } catch (Throwable e) {
       logger.error("Cannot bind to EIP", e);
       Thread.sleep(EIP_BIND_SLEEP_TIME_MS);
     }
   }
   // Schedule a timer which periodically checks for EIP binding.
   timer.schedule(new EIPBindingTask(), serverConfig.getEIPBindingRetryIntervalMsWhenUnbound());
 }
Exemple #2
0
  /**
   * Gets the EC2 service object to call AWS APIs.
   *
   * @return the EC2 service object to call AWS APIs.
   */
  private AmazonEC2 getEC2Service() {
    String aWSAccessId = serverConfig.getAWSAccessId();
    String aWSSecretKey = serverConfig.getAWSSecretKey();

    AmazonEC2 ec2Service;
    if (null != aWSAccessId
        && !"".equals(aWSAccessId)
        && null != aWSSecretKey
        && !"".equals(aWSSecretKey)) {
      ec2Service = new AmazonEC2Client(new BasicAWSCredentials(aWSAccessId, aWSSecretKey));
    } else {
      ec2Service = new AmazonEC2Client(new InstanceProfileCredentialsProvider());
    }

    String region = clientConfig.getRegion();
    region = region.trim().toLowerCase();
    ec2Service.setEndpoint("ec2." + region + ".amazonaws.com");
    return ec2Service;
  }
Exemple #3
0
 @PreDestroy
 public void shutdown() throws Exception {
   timer.cancel();
   for (int i = 0; i < serverConfig.getEIPBindRebindRetries(); i++) {
     try {
       unbindEIP();
       break;
     } catch (Exception e) {
       logger.warn("Cannot unbind the EIP from the instance");
       Thread.sleep(1000);
     }
   }
 }
  public static EurekaServerConfig newEurekaServerConfig() {
    EurekaServerConfig config = mock(EurekaServerConfig.class);

    // Cluster management related
    when(config.getPeerEurekaNodesUpdateIntervalMs())
        .thenReturn((int) EUREKA_NODES_UPDATE_INTERVAL_MS);

    // Replication logic related
    when(config.shouldSyncWhenTimestampDiffers()).thenReturn(true);
    when(config.getMaxTimeForReplication()).thenReturn((int) REPLICATION_EXPIRY_TIME_MS);
    when(config.getMaxElementsInPeerReplicationPool()).thenReturn(10);
    when(config.getMaxElementsInStatusReplicationPool()).thenReturn(10);
    when(config.getMaxThreadsForPeerReplication()).thenReturn(1);
    when(config.getMaxThreadsForStatusReplication()).thenReturn(1);

    return config;
  }