Beispiel #1
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);
  }
Beispiel #2
0
  /**
   * Update member status to initialized and publish member initialized event
   *
   * @param memberContext
   */
  public static void handleMemberInitializedEvent(MemberContext memberContext) {
    Topology topology = TopologyManager.getTopology();
    Service service = topology.getService(memberContext.getCartridgeType());
    if (service == null) {
      log.warn(String.format("Service %s does not exist", memberContext.getCartridgeType()));
      return;
    }
    if (!service.clusterExists(memberContext.getClusterId())) {
      log.warn(
          String.format(
              "Cluster %s does not exist in service %s",
              memberContext.getClusterId(), memberContext.getCartridgeType()));
      return;
    }

    Member member =
        service.getCluster(memberContext.getClusterId()).getMember(memberContext.getMemberId());
    if (member == null) {
      log.warn(String.format("Member %s does not exist", memberContext.getMemberId()));
      return;
    }

    try {
      TopologyManager.acquireWriteLock();

      // Set ip addresses
      member.setDefaultPrivateIP(memberContext.getDefaultPrivateIP());
      if (memberContext.getPrivateIPs() != null) {
        member.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs()));
      }
      member.setDefaultPublicIP(memberContext.getDefaultPublicIP());
      if (memberContext.getPublicIPs() != null) {
        member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs()));
      }

      // try update lifecycle state
      if (!member.isStateTransitionValid(MemberStatus.Initialized)) {
        log.error(
            "Invalid state transition from "
                + member.getStatus()
                + " to "
                + MemberStatus.Initialized);
        return;
      } else {
        member.setStatus(MemberStatus.Initialized);
        log.info("Member status updated to initialized");

        TopologyManager.updateTopology(topology);

        TopologyEventPublisher.sendMemberInitializedEvent(memberContext);
        // publishing data
        BAMUsageDataPublisher.publish(
            memberContext.getMemberId(),
            memberContext.getPartition().getId(),
            memberContext.getNetworkPartitionId(),
            memberContext.getClusterId(),
            memberContext.getCartridgeType(),
            MemberStatus.Initialized.toString(),
            null);
      }
    } finally {
      TopologyManager.releaseWriteLock();
    }
  }