예제 #1
0
  private void updateMemberContext(
      MemberContext memberContext, Pod pod, KubernetesCluster kubernetesCluster) {

    String memberPrivateIPAddress = pod.getStatus().getPodIP();
    String podHostIPAddress = pod.getStatus().getHostIP();
    String memberPublicIPAddress = podHostIPAddress;
    String kubernetesHostPublicIP =
        findKubernetesHostPublicIPAddress(kubernetesCluster, podHostIPAddress);

    if (StringUtils.isNotBlank(kubernetesHostPublicIP)) {
      memberPublicIPAddress = kubernetesHostPublicIP;
      if (log.isInfoEnabled()) {
        log.info(
            String.format(
                "Member public IP address set to kubernetes host public IP address:"
                    + "[pod-host-ip] %s [kubernetes-host-public-ip] %s",
                podHostIPAddress, kubernetesHostPublicIP));
      }
    }

    memberContext.setInstanceId(pod.getMetadata().getName());
    memberContext.setDefaultPrivateIP(memberPrivateIPAddress);
    memberContext.setPrivateIPs(new String[] {memberPrivateIPAddress});
    memberContext.setDefaultPublicIP(memberPublicIPAddress);
    memberContext.setPublicIPs(new String[] {memberPublicIPAddress});
    memberContext.setInitTime(memberContext.getInitTime());
    memberContext.setProperties(memberContext.getProperties());
  }
예제 #2
0
  /**
   * Add member object to the topology and publish member created event
   *
   * @param memberContext
   */
  public static void handleMemberCreatedEvent(MemberContext memberContext) {
    Topology topology = TopologyManager.getTopology();

    Service service = topology.getService(memberContext.getCartridgeType());
    String clusterId = memberContext.getClusterId();
    Cluster cluster = service.getCluster(clusterId);
    String memberId = memberContext.getMemberId();
    String clusterInstanceId = memberContext.getClusterInstanceId();
    String networkPartitionId = memberContext.getNetworkPartitionId();
    String partitionId = memberContext.getPartition().getId();
    String lbClusterId = memberContext.getLbClusterId();
    long initTime = memberContext.getInitTime();

    if (cluster.memberExists(memberId)) {
      log.warn(String.format("Member %s already exists", memberId));
      return;
    }

    try {
      TopologyManager.acquireWriteLock();
      Member member =
          new Member(
              service.getServiceName(),
              clusterId,
              memberId,
              clusterInstanceId,
              networkPartitionId,
              partitionId,
              memberContext.getLoadBalancingIPType(),
              initTime);
      member.setStatus(MemberStatus.Created);
      member.setLbClusterId(lbClusterId);
      member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
      cluster.addMember(member);
      TopologyManager.updateTopology(topology);
    } finally {
      TopologyManager.releaseWriteLock();
    }

    TopologyEventPublisher.sendMemberCreatedEvent(memberContext);
  }