Example #1
0
  public static void handleClusterRemoved(ClusterContext ctxt) {
    Topology topology = TopologyManager.getTopology();
    Service service = topology.getService(ctxt.getCartridgeType());
    String deploymentPolicy;
    if (service == null) {
      log.warn(String.format("Service %s does not exist", ctxt.getCartridgeType()));
      return;
    }

    if (!service.clusterExists(ctxt.getClusterId())) {
      log.warn(
          String.format(
              "Cluster %s does not exist for service %s",
              ctxt.getClusterId(), ctxt.getCartridgeType()));
      return;
    }

    try {
      TopologyManager.acquireWriteLock();
      Cluster cluster = service.removeCluster(ctxt.getClusterId());
      deploymentPolicy = cluster.getDeploymentPolicyName();
      TopologyManager.updateTopology(topology);
    } finally {
      TopologyManager.releaseWriteLock();
    }
    TopologyEventPublisher.sendClusterRemovedEvent(ctxt, deploymentPolicy);
  }
Example #2
0
  public static void handleMemberStarted(InstanceStartedEvent instanceStartedEvent) {
    try {
      Topology topology = TopologyManager.getTopology();
      Service service = topology.getService(instanceStartedEvent.getServiceName());
      if (service == null) {
        log.warn(String.format("Service %s does not exist", instanceStartedEvent.getServiceName()));
        return;
      }
      if (!service.clusterExists(instanceStartedEvent.getClusterId())) {
        log.warn(
            String.format(
                "Cluster %s does not exist in service %s",
                instanceStartedEvent.getClusterId(), instanceStartedEvent.getServiceName()));
        return;
      }

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

      try {
        TopologyManager.acquireWriteLock();
        // try update lifecycle state
        if (!member.isStateTransitionValid(MemberStatus.Starting)) {
          log.error(
              "Invalid State Transition from "
                  + member.getStatus()
                  + " to "
                  + MemberStatus.Starting);
          return;
        } else {
          member.setStatus(MemberStatus.Starting);
          log.info("member started event adding status started");

          TopologyManager.updateTopology(topology);
          // memberStartedEvent.
          TopologyEventPublisher.sendMemberStartedEvent(instanceStartedEvent);
          // publishing data
          BAMUsageDataPublisher.publish(
              instanceStartedEvent.getMemberId(),
              instanceStartedEvent.getPartitionId(),
              instanceStartedEvent.getNetworkPartitionId(),
              instanceStartedEvent.getClusterId(),
              instanceStartedEvent.getServiceName(),
              MemberStatus.Starting.toString(),
              null);
        }
      } finally {
        TopologyManager.releaseWriteLock();
      }
    } catch (Exception e) {
      String message =
          String.format(
              "Could not handle member started event: [application-id] %s "
                  + "[service-name] %s [member-id] %s",
              instanceStartedEvent.getApplicationId(),
              instanceStartedEvent.getServiceName(),
              instanceStartedEvent.getMemberId());
      log.warn(message, e);
    }
  }
Example #3
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();
    }
  }