Beispiel #1
0
  public static void handleMemberReadyToShutdown(
      InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
      throws InvalidMemberException, InvalidCartridgeTypeException {
    Topology topology = TopologyManager.getTopology();
    Service service = topology.getService(instanceReadyToShutdownEvent.getServiceName());
    // update the status of the member
    if (service == null) {
      log.warn(
          String.format(
              "Service %s does not exist", instanceReadyToShutdownEvent.getServiceName()));
      return;
    }

    Cluster cluster = service.getCluster(instanceReadyToShutdownEvent.getClusterId());
    if (cluster == null) {
      log.warn(
          String.format("Cluster %s does not exist", instanceReadyToShutdownEvent.getClusterId()));
      return;
    }

    Member member = cluster.getMember(instanceReadyToShutdownEvent.getMemberId());
    if (member == null) {
      log.warn(
          String.format("Member %s does not exist", instanceReadyToShutdownEvent.getMemberId()));
      return;
    }
    MemberReadyToShutdownEvent memberReadyToShutdownEvent =
        new MemberReadyToShutdownEvent(
            instanceReadyToShutdownEvent.getServiceName(),
            instanceReadyToShutdownEvent.getClusterId(),
            instanceReadyToShutdownEvent.getClusterInstanceId(),
            instanceReadyToShutdownEvent.getMemberId(),
            instanceReadyToShutdownEvent.getNetworkPartitionId(),
            instanceReadyToShutdownEvent.getPartitionId());
    try {
      TopologyManager.acquireWriteLock();

      if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
        log.error(
            "Invalid State Transition from "
                + member.getStatus()
                + " to "
                + MemberStatus.ReadyToShutDown);
        return;
      }
      member.setStatus(MemberStatus.ReadyToShutDown);
      log.info("Member Ready to shut down event adding status started");

      TopologyManager.updateTopology(topology);
    } finally {
      TopologyManager.releaseWriteLock();
    }
    TopologyEventPublisher.sendMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
    // publishing data
    BAMUsageDataPublisher.publish(
        instanceReadyToShutdownEvent.getMemberId(),
        instanceReadyToShutdownEvent.getPartitionId(),
        instanceReadyToShutdownEvent.getNetworkPartitionId(),
        instanceReadyToShutdownEvent.getClusterId(),
        instanceReadyToShutdownEvent.getServiceName(),
        MemberStatus.ReadyToShutDown.toString(),
        null);
    // termination of particular instance will be handled by autoscaler
  }