Exemple #1
0
  public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
    Topology topology = TopologyManager.getTopology();

    for (Cartridge cartridge : cartridgeList) {
      Service service = topology.getService(cartridge.getType());
      if (service == null) {
        log.warn("Cartridge does not exist [cartidge] " + cartridge);
        return;
      }
      if (service.getClusters().size() == 0) {
        if (topology.serviceExists(cartridge.getType())) {
          try {
            TopologyManager.acquireWriteLock();
            topology.removeService(cartridge.getType());
            TopologyManager.updateTopology(topology);
          } finally {
            TopologyManager.releaseWriteLock();
          }
          TopologyEventPublisher.sendServiceRemovedEvent(cartridgeList);
        } else {
          log.warn(String.format("Service %s does not exist..", cartridge.getType()));
        }
      } else {
        log.warn(
            "Subscription already exists. Hence not removing the service:"
                + cartridge.getType()
                + " from the topology");
      }
    }
  }
Exemple #2
0
  public static void handleServiceCreated(List<Cartridge> cartridgeList) {
    Service service;
    Topology topology = TopologyManager.getTopology();
    if (cartridgeList == null) {
      log.warn(String.format("Cartridge list is empty"));
      return;
    }

    try {

      TopologyManager.acquireWriteLock();
      for (Cartridge cartridge : cartridgeList) {
        if (!topology.serviceExists(cartridge.getType())) {
          ServiceType serviceType =
              cartridge.isMultiTenant() ? ServiceType.MultiTenant : ServiceType.SingleTenant;
          service = new Service(cartridge.getType(), serviceType);
          Properties properties = new Properties();

          try {
            Property[] propertyArray = null;

            if (cartridge.getProperties() != null) {
              if (cartridge.getProperties().getProperties() != null) {
                propertyArray = cartridge.getProperties().getProperties();
              }
            }

            List<Property> propertyList = new ArrayList<Property>();
            if (propertyArray != null) {
              propertyList = Arrays.asList(propertyArray);
              if (propertyList != null) {
                for (Property property : propertyList) {
                  properties.setProperty(property.getName(), property.getValue());
                }
              }
            }
          } catch (Exception e) {
            log.error(e);
          }

          service.setProperties(properties);
          if (cartridge.getPortMappings() != null) {
            List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
            Port port;
            // adding ports to the event
            for (PortMapping portMapping : portMappings) {
              port =
                  new Port(
                      portMapping.getProtocol(), portMapping.getPort(), portMapping.getProxyPort());
              service.addPort(port);
            }
          }

          topology.addService(service);
          TopologyManager.updateTopology(topology);
        }
      }
    } finally {
      TopologyManager.releaseWriteLock();
    }
    TopologyEventPublisher.sendServiceCreateEvent(cartridgeList);
  }