Exemple #1
0
  public static void handleApplicationClustersCreated(String appId, List<Cluster> appClusters) {

    TopologyManager.acquireWriteLock();

    try {
      Topology topology = TopologyManager.getTopology();
      for (Cluster cluster : appClusters) {
        Service service = topology.getService(cluster.getServiceName());
        if (service == null) {
          log.error(
              "Service "
                  + cluster.getServiceName()
                  + " not found in Topology, unable to create Application cluster");
        } else {
          service.addCluster(cluster);
          log.info("Application Cluster " + cluster.getClusterId() + " created in CC topology");
        }
      }
      TopologyManager.updateTopology(topology);
    } finally {
      TopologyManager.releaseWriteLock();
    }

    log.debug("Creating cluster port mappings: [appication-id] " + appId);
    for (Cluster cluster : appClusters) {
      String cartridgeType = cluster.getServiceName();
      Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
      if (cartridge == null) {
        throw new CloudControllerException(
            "Cartridge not found: [cartridge-type] " + cartridgeType);
      }

      for (PortMapping portMapping : cartridge.getPortMappings()) {
        ClusterPortMapping clusterPortMapping =
            new ClusterPortMapping(
                appId,
                cluster.getClusterId(),
                portMapping.getName(),
                portMapping.getProtocol(),
                portMapping.getPort(),
                portMapping.getProxyPort());
        if (portMapping.getKubernetesPortType() != null) {
          clusterPortMapping.setKubernetesServiceType(portMapping.getKubernetesPortType());
        }
        CloudControllerContext.getInstance().addClusterPortMapping(clusterPortMapping);
        log.debug("Cluster port mapping created: " + clusterPortMapping.toString());
      }
    }

    // Persist cluster port mappings
    CloudControllerContext.getInstance().persist();

    // Send application clusters created event
    TopologyEventPublisher.sendApplicationClustersCreated(appId, appClusters);
  }