예제 #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);
  }
  private boolean doProcess(ClusterCreatedEvent event, Topology topology) {
    Cluster cluster = event.getCluster();
    String applicationId = cluster.getAppId();
    String serviceName = cluster.getServiceName();
    String clusterId = cluster.getClusterId();

    // Apply application filter
    if (TopologyApplicationFilter.apply(applicationId)) {
      return false;
    }

    // Apply service filter
    if (TopologyServiceFilter.apply(serviceName)) {
      return false;
    }

    // Apply cluster filter
    if (TopologyClusterFilter.apply(clusterId)) {
      return false;
    }

    // Validate event against the existing topology
    Service service = topology.getService(serviceName);
    if (service == null) {
      if (log.isWarnEnabled()) {
        log.warn(String.format("Service does not exist: [service] %s", serviceName));
      }
      return false;
    }
    if (service.clusterExists(clusterId)) {
      if (log.isDebugEnabled()) {
        log.debug(
            String.format(
                "Cluster already exists in service: [service] %s " + "[cluster] %s",
                serviceName, clusterId));
      }
    } else {

      // Apply changes to the topology
      service.addCluster(cluster);
      if (log.isInfoEnabled()) {
        log.info(String.format("Cluster created: %s", cluster.toString()));
      }
    }

    // Notify event listeners
    notifyEventListeners(event);
    return true;
  }
예제 #3
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);
    }
  }
예제 #4
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();
    }
  }